-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.py
More file actions
48 lines (40 loc) · 1.37 KB
/
github.py
File metadata and controls
48 lines (40 loc) · 1.37 KB
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
import threading
import urllib.request
import json
class GitHub:
@staticmethod
def _request(url, then=None, error=None):
try:
response = urllib.request.urlopen(url)
if (then):
body = response.read().decode('utf-8')
then(json.loads(body))
return response
except Exception as e:
if (error):
error(e)
else:
raise e
@staticmethod
def _request_thread(url, then, error):
thread = threading.Thread(target=GitHub._request, args=[url, then, error])
thread.start()
@staticmethod
def _download(url, filepath, then, error):
try:
urllib.request.urlretrieve(url, filepath)
then()
except Exception as e:
error(e)
@staticmethod
def get_releases(then, error):
url = 'https://api.github.com/repos/open-stage/blender-dmx/releases'
return GitHub._request_thread(url, then, error)
@staticmethod
def get_branches(then, error):
url = 'https://api.github.com/repos/open-stage/blender-dmx/branches'
return GitHub._request_thread(url, then, error)
@staticmethod
def download(url, filepath, then, error):
thread = threading.Thread(target=GitHub._download, args=[url, filepath, then, error])
thread.start()