-
Notifications
You must be signed in to change notification settings - Fork 2
/
github.py
36 lines (26 loc) · 1.08 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
import requests
import json
api = "https://api.github.com"
def get_request(path, params=None):
if not params:
params = {}
r = requests.get("%s%s" % (api, path), params=params)
return r.json()
def save_issues_to_json(repo_owner, repo_name, filename):
args = { 'owner' : repo_owner, 'name' : repo_name }
path = "/repos/%(owner)s/%(name)s/issues" % args
issues = {}
raw_json_data = get_request(path, {'state' : 'open' })
issues.update(dict((issue['number'], issue) for issue in raw_json_data))
raw_json_data = get_request(path, {'state' : 'closed' })
issues.update(dict((issue['number'], issue) for issue in raw_json_data))
with open(filename, "wb") as f:
json.dump(issues, f)
try:
save_issues_to_json("dexy", "dexy", "issues.json")
save_issues_to_json("dexy", "dexy-user-guide", "docs-issues.json")
except requests.exceptions.ConnectionError:
import shutil
backups = "/Users/ana/dev/dexy-user-guide/offline-backups/"
for f in ["issues.json", "docs-issues.json"]:
shutil.copyfile(backups + f, f)