-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.py
203 lines (148 loc) · 5.41 KB
/
github.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
from colorama import init, Style, Fore, Back
import sys, itertools, threading, time, requests
from pprint import pprint
from tabulate import tabulate
from Spinner import Spinner
init(autoreset=True)
API_URL = 'https://api.github.com/'
API_URL_1 = 'https://api.github.com/users/'
usage = 'python github.py <username>\npython github.py <username> <reponame>'
example = '> python github.py hashimshafiq'
contribute = "Contribute to this project"
def argumentError():
print(Style.BRIGHT + Fore.RED + "Argument Missing")
print(Style.BRIGHT + Fore.YELLOW + "Usage:")
print(Style.BRIGHT + Fore.CYAN + usage)
print(Style.BRIGHT + Fore.YELLOW + "Example:")
print(Style.BRIGHT + Fore.CYAN + example)
def getUSERDATA(username):
spinner = Spinner()
spinner.start()
print(Fore.YELLOW + Style.BRIGHT + "Getting information about user ",end='')
print(Fore.RED + Style.BRIGHT + username)
url = API_URL + 'users/'+username
response = requests.get(url)
if(response.status_code==200):
print(Style.BRIGHT + Fore.GREEN + "Successfull...")
elif(response.status_code==404):
print(Style.BRIGHT + Fore.RED + "username not found")
spinner.stop()
sys.exit()
elif(response.status_code==403):
print(Style.BRIGHT + Fore.RED + "Warning: Maximum Number of Ateempts Limit Crossed")
spinner.stop()
sys.exit()
data = response.json()
spinner.stop()
if(data['login']):
print(Style.BRIGHT+Fore.CYAN + "\nUsername: ",end='')
print(Style.BRIGHT+data['login'])
if(data['name']):
print(Style.BRIGHT+Fore.CYAN +"Name: ",end='')
print(Style.BRIGHT+data['name'])
if(data['company']):
print(Style.BRIGHT+Fore.CYAN +"Company: ",end='')
print(Style.BRIGHT+data['company'])
if(data['bio']):
print(Style.BRIGHT+Fore.CYAN +"Bio: ",end='')
print(Style.BRIGHT+data['bio'])
if(data['blog']):
print(Style.BRIGHT+Fore.CYAN +"Blog: ",end='')
print(Style.BRIGHT+data['blog'])
if(data['location']):
print(Style.BRIGHT+Fore.CYAN +"Location: ",end='')
print(Style.BRIGHT+data['location'])
if(data['html_url']):
print(Style.BRIGHT+Fore.CYAN +"Github Profile: ",end='')
print(Style.BRIGHT+data['html_url'])
headers = ["Public Repos","Public Gists","Followers","Following"]
table = [[data['public_repos'],data['public_gists'],data['followers'],data['following']]]
print(tabulate(table, headers, tablefmt="fancy_grid",numalign='center'))
def getREPODATA(username,reponame):
spinner = Spinner()
spinner.start()
print(Fore.YELLOW + Style.BRIGHT + "Getting information about repo ",end='')
print(Fore.RED + Style.BRIGHT + reponame)
url = API_URL + 'repos/'+username+'/'+reponame
response = requests.get(url)
if(response.status_code==200):
print(Style.BRIGHT + Fore.GREEN + "Successfull...")
elif(response.status_code==404):
print(Style.BRIGHT + Fore.RED + "username or repo not found")
spinner.stop()
sys.exit()
elif(response.status_code==403):
print(Style.BRIGHT + Fore.RED + "Warning: Maximum Number of Ateempts Limit Crossed")
spinner.stop()
sys.exit()
data = response.json()
spinner.stop()
if(data['name']):
print(Style.BRIGHT+Fore.CYAN + "\nRepository Name: ",end='')
print(Style.BRIGHT+data['name'])
if(data['description']):
print(Style.BRIGHT+Fore.CYAN +"Description: ",end='')
print(Style.BRIGHT+data['description'])
if(data['homepage']):
print(Style.BRIGHT+Fore.CYAN +"Project HomePage: ",end='')
print(Style.BRIGHT+data['homepage'])
if(data['html_url']):
print(Style.BRIGHT+Fore.CYAN +"Github Link: ",end='')
print(Style.BRIGHT+data['html_url'])
if('parent' in data.keys()):
print()
print(Style.BRIGHT+Fore.CYAN+"This repo is forked from ",end='')
print(Style.BRIGHT+data['parent']['owner']['login'])
print(Style.BRIGHT+Fore.CYAN+"Origial Owner: ",end='')
print(Style.BRIGHT+data['parent']['owner']['login'])
print(Style.BRIGHT+Fore.CYAN+"Original Github Link: ",end='')
print(Style.BRIGHT+data['parent']['html_url'])
headers = ["Language","Watching","Stars","Forks","Issues","Size (KB)","Default Branch"]
table = [[data['language'],data['subscribers_count'],data['stargazers_count'],data['forks_count'],data['open_issues_count'],data['size'],data['default_branch']]]
print(tabulate(table, headers, tablefmt="fancy_grid",numalign='center'))
def getALLREPOS(username):
spinner = Spinner()
spinner.start()
print(Fore.YELLOW + Style.BRIGHT + "Getting information about all repo of user ",end='')
print(Fore.RED + Style.BRIGHT + username)
count = 0
boolean=True
while boolean:
url = API_URL_1 +username+'/repos'
payload = {'type': 'all','page':count,'per_page':100}
response = requests.get(url,payload)
if(response.status_code==200):
print(Style.BRIGHT + Fore.GREEN + "Successfull...")
elif(response.status_code==404):
print(Style.BRIGHT + Fore.RED + "username or repo not found")
spinner.stop()
sys.exit()
elif(response.status_code==403):
print(Style.BRIGHT + Fore.RED + "Warning: Maximum Number of Ateempts Limit Crossed")
spinner.stop()
sys.exit()
link = response.headers.get('link',None)
data = response.json()
spinner.stop()
for d in data:
print(d['name'])
if link is None:
boolean=False
count = count + 1
spinner.stop()
def main():
if(len(sys.argv)==2):
username = sys.argv[1]
getUSERDATA(username)
elif(len(sys.argv)==3):
username = sys.argv[1]
reponame = sys.argv[2]
if(reponame != '*'):
getREPODATA(username,reponame)
else:
getALLREPOS(username)
else:
argumentError()
sys.exit()
if __name__ == "__main__":
main()