-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
53 lines (45 loc) · 1.53 KB
/
main.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
import json
import github
DEFAULT_PAGE_SIZE = 30
def pretty_print(d): return print(json.dumps(d, indent=4, sort_keys=True))
def get_page_size(search):
ar = search.split('~')
if len(ar) > 1:
return ar[1].split('page_size=')[1]
else:
return DEFAULT_PAGE_SIZE
def github_encode(s):
"""Github encode strings so for example
"bootstrap frontend" => "bootstrap+frontend"
"""
return '+'.join(s.split())
def main():
while (True):
print("option flags, specify page size: ~page_size=50")
search = input('Please Enter a Search Term or type `:q` to quit: ')
# validate input
search = github_encode(search.split('~')[0])
print(search, github_encode(search))
if len(search)==0:
continue
per_page = get_page_size(search)
push_mode = input('Push Mode On? Y/N - (CTR+C to exit): ')
if push_mode.lower() == 'y':
print('Starting Unlimited Streaming for: {}'.format(search))
page_counter = 1
while True:
pretty_print(github.search_repositories(search, per_page, page=page_counter, counter=0))
page_counter +=1
github.rate_limit_queue(10) # Rate limits by one query per set seconds
else:
pretty_print(github.search_repositories(search, per_page))
if search == ':q':
break
print('Goodbye!')
if __name__ == "__main__":
fail_execution = 0
try:
main()
except:
fail_execution += 1
main()