-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
91 lines (63 loc) · 3.23 KB
/
api.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
import requests
import constants
import utils
import wget
headers = {
}
def GetRepoDataInJson(owner, repo):
return requests.get(f"{constants.GITHUB_ENDPOINT}/{owner}/{repo}", headers=headers).json()
def GetRepoReleasesInJson(owner, repo):
return requests.get(f"{constants.GITHUB_ENDPOINT}/{owner}/{repo}/releases", headers=headers).json()
def PrettyPrintRepo(repoData):
if repoData['license'] == None:
licenseData = "None"
else:
licenseData = repoData['license']['name']
F = [
constants.COLOR_GREEN, f" Owner: {repoData['owner']['login']:<20} ", constants.END_LINE,
constants.COLOR_BLUE, f" Description: {repoData['description']:<20} ", constants.END_LINE,
constants.COLOR_PURPLE, f" Created: {repoData['created_at']:<20} ", constants.END_LINE,
constants.COLOR_RED, f" License: {licenseData:<20} ", constants.END_LINE,
constants.COLOR_CYAN, f" Install: {str(repoData['name']).upper():<20} ", constants.END_COLOR, constants.END_LINE
]
utils.pm(F)
def SplitOwnerRepo(url): return url.split("/")[-2:]
def ListProjects():
for value in constants.PROJECTS.values():
owner, repo = SplitOwnerRepo(value)
PrettyPrintRepo(GetRepoDataInJson(owner, repo))
def DownloadFile(url): return wget.download(url)
def DownloadLatestRelease(repo):
for key in constants.PROJECTS:
if key == repo:
owner, repo = SplitOwnerRepo(constants.PROJECTS[key])
releases = GetRepoReleasesInJson(owner, repo)
latest = releases[0]
release_url = latest['html_url']
release_notes = latest['body']
created = latest['created_at']
version = latest['tag_name']
assets= latest['assets']
if (len(assets) > 0):
for asset in latest['assets']:
if asset['content_type']:
if asset['content_type'] in constants.ACCEPTED_CONTENT_TYPES:
link = asset['browser_download_url']
size = int(asset['size'])/1048576
size = "%.2fMB" % size
else:
link = latest['tarball_url']
size = "N/A"
F = [
constants.COLOR_BLUE, f" ", constants.END_LINE,
f" Release Notes:\n {release_notes:<20} ", constants.END_LINE,
constants.COLOR_GREEN, f" Url: {release_url:<20} ", constants.END_LINE,
constants.COLOR_PURPLE, f" Created: {created:<20} ", constants.END_LINE,
constants.COLOR_RED, f" Version: {version:<20} ", constants.END_LINE,
constants.COLOR_RED, f" Link: {link:<20} ", constants.END_LINE,
constants.COLOR_CYAN, f" Size: {size:<20} ", constants.END_COLOR, constants.END_LINE
]
utils.pm(F)
choice = input(" Enter (Y/n) to download: ")
if not choice == "n":
return DownloadFile(link)