-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawler.py
46 lines (34 loc) · 993 Bytes
/
crawler.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
#!/usr/bin/python
import json
import requests
import time
import database
'''
Github unsecured API crawler
@author Misha Frenkman
@version 0.1
'''
githubURL = "https://api.github.com/repositories?since="
def checkReset():
url = "https://api.github.com/rate_limit"
resetDate = requests.get(url).json()[u'rate'][u'reset']
return int(round((resetDate - time.time()) / 60))+1
def crawler():
startID = 0
while True:
startID = database.checkLastID() or 0
req = githubURL+str(startID)
res = requests.get(req).json()
#Check for the right Github response
if type(res) is list:
#Iterate Repos
for repo in res:
# Check for private
if repo[u'private'] == False:
#Insert Repo in Database
database.insertRepo(repo[u'id'], repo[u'full_name'], repo[u'html_url'])
else:
print "Github kicked me out :( Rate limit reset in: %i minutes" % (checkReset())
print "Timestamp: %s" % (time.strftime("%d.%m.%Y %H:%M:%S"))
time.sleep(60*10)
crawler()