├── .gitignore ├── README.md └── eyegit.py /.gitignore: -------------------------------------------------------------------------------- 1 | api_config 2 | users.config 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitStalker 2 | Stalk/Track whoever you want on Github 3 | 4 | No longer do you have to scour that list of profiles to see what they're upto. Just add those usernames to the users.config file, and sit back as the simple script scours the depths of Github for you. 5 | 6 | P.S: The script is quite basic, but hey I saved you from having to type it :) 7 | Upcoming features: 8 | 1. Currently shows last 30 days. Later will add ability to only show diff from the last time you ran it. 9 | 2. Will add support for other events if needed. Currently just tracks commits. 10 | 11 | Possible bugs: 12 | 1. May not work for certain accounts if their Git config isn't the same as their Github configuration. Will remedy this in the future 13 | -------------------------------------------------------------------------------- /eyegit.py: -------------------------------------------------------------------------------- 1 | # Data is array of responses 2 | import requests 3 | import iso8601 4 | import configparser 5 | import os 6 | config = configparser.ConfigParser() 7 | 8 | current_path = os.path.dirname(__file__) 9 | api_config_path = os.path.join(current_path, "api_config") 10 | config.read(api_config_path) 11 | 12 | # import argparse 13 | file_name = os.path.join(current_path, "users.config") 14 | event = "PushEvent" 15 | token = config["DEFAULT"]["github_token"] 16 | def user_events_url(user): 17 | return "https://api.github.com/users/"+user+"/events" 18 | 19 | def get_data(users): 20 | data = []; 21 | for user in users: 22 | user_data = [] 23 | response = requests.get( 24 | user_events_url(user), 25 | headers = {'Authorization': token} 26 | ) 27 | last = 1 28 | if('links' in response.links): 29 | url = response.links["last"]["url"] 30 | last = int(url[url.find("?page=")+len("?page="):]) 31 | response = response.json() 32 | month = iso8601.parse_date(response[0]["created_at"]).month 33 | user_data.extend(response) 34 | page = 2 35 | while(iso8601.parse_date(response[len(response)-1]["created_at"]).month>month-1 and page < last): 36 | response = requests.get( 37 | user_events_url(user), 38 | params = {'page': page}, 39 | headers = {'Authorization': token} 40 | ).json() 41 | page = page + 1 42 | user_data.extend(response) 43 | data.append(user_data) 44 | return data 45 | def filter_by_event(events, event_type): 46 | return list(filter(lambda x: x["type"] == event_type, events)) 47 | def filter_by_author(commits, authors): 48 | tmp = [] 49 | for author in authors: 50 | tmp.extend(list((filter(lambda x: x["author"]["name"] == author, commits)))); 51 | return tmp 52 | # def filter_by_date(events, date): 53 | 54 | def return_users_from_file(path): 55 | file = open(path,"r") 56 | users=[] 57 | line = file.readline() 58 | while(len(line)>0): 59 | line = line.splitlines()[0] 60 | line = line.strip() 61 | if(len(line)>0): 62 | users.append(line) 63 | line = file.readline() 64 | return users 65 | # user = input() 66 | def get_name_url(name): 67 | return "https://api.github.com/users/"+name 68 | def get_name(name): 69 | return requests.get(get_name_url(name), headers = {'Authorization': token}).json()["name"] 70 | def remove_empty(data): 71 | return list(filter(lambda item: len(item["payload"]["commits"])>0, data)) 72 | def print_item(data): 73 | for item in data: 74 | print("{} has pushed {} commits to {}".format(item["actor"]["login"], len(item["payload"]["commits"]), item["repo"]["name"])) 75 | if __name__ == "__main__": 76 | users = return_users_from_file(file_name) 77 | data = get_data(users) 78 | for index,item in enumerate(data): 79 | data[index] = list(filter_by_event(item, event)); 80 | data = list(filter(lambda item: len(item)>0, data)); 81 | for response in data: 82 | author_name = get_name(response[0]["actor"]["login"]) 83 | for item in response: 84 | # print(item) 85 | item["payload"]["commits"] = filter_by_author(item["payload"]["commits"],[item["actor"]["login"], author_name]) 86 | 87 | for index, item in enumerate(data): 88 | data[index] = remove_empty(item) 89 | author_commit = {} 90 | for user in data: 91 | for item in user: 92 | author_key = item["actor"]["login"] 93 | repo_key = item["repo"]["name"] 94 | if author_key not in author_commit: 95 | author_commit[author_key] = {} 96 | if repo_key not in author_commit[author_key]: 97 | author_commit[author_key][repo_key] = 0 98 | author_commit[author_key][repo_key] += len(item["payload"]["commits"]) 99 | 100 | for author in author_commit: 101 | for repo in author_commit[author]: 102 | print("{} has pushed {} commits to {}".format(author, author_commit[author][repo], repo)) 103 | 104 | 105 | # print(data) 106 | 107 | 108 | # data = get_data([user]); 109 | 110 | # for event in filter_by_event(data[0], "PushEvent"): 111 | # commits = event["payload"]["commits"]; 112 | # event["payload"]["commits"] = filter_by_author(commits, ["kishore-ganesh", "Kalpaj Aggrawala"]) 113 | 114 | 115 | # Add difference between previous run and this return 116 | # Read from file 117 | #Name filter problems 118 | #On Each run, store the results. On next run, just give the diff, i.e filter y dat 119 | #Let it go back one month 120 | #Group together commits from same repo 121 | --------------------------------------------------------------------------------