forked from dhtdht020/osc-dl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsecontents.py
148 lines (114 loc) · 4.12 KB
/
parsecontents.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import requests
import json
import download
import metadata
from halo import Halo
FAIL = '\033[91m'
# Get list of apps from repo metadata
def get(repo="hbb1.oscwii.org", raw=False):
if raw is False:
with Halo(text="Getting list..", color="yellow", text_color="yellow"):
try:
u = requests.get("https://" + repo + "/metadata.json")
except requests.exceptions.SSLError:
u = requests.get("http://" + repo + "/metadata.json")
else:
try:
u = requests.get("https://" + repo + "/metadata.json")
except requests.exceptions.SSLError:
u = requests.get("http://" + repo + "/metadata.json")
data = json.loads(u.content)
for key in data.keys():
print(key)
def query(term, repo="hbb1.oscwii.org"):
print("Searching for package on " + repo + "..")
with Halo(text="Searching..", color="yellow", text_color="yellow"):
try:
try:
u = requests.get("https://" + repo + "/metadata.json")
except requests.exceptions.SSLError:
u = requests.get("http://" + repo + "/metadata.json")
except requests.exceptions.ConnectionError:
print("Could not connect to host: "+ repo)
exit(1)
try:
data = json.loads(u.content)
except json.decoder.JSONDecodeError:
print("[Error P:001] Could not parse list from metadata JSON.")
exit(1)
found = "false"
for key in data.keys():
if key == term:
found = "true"
if found == "true":
print("Found package!")
return True
else:
print(FAIL+'Could not find "' + term + '" on the repository. :(')
def query_verify(term, repo="hbb1.oscwii.org", internal=False):
try:
u = requests.get("https://" + repo + "/metadata.json")
except requests.exceptions.SSLError:
u = requests.get("http://" + repo + "/metadata.json")
data = json.loads(u.content)
found = "false"
for key in data.keys():
if key == term:
found = "true"
if internal is False:
if found == "true":
return print("True")
else:
return print("False")
else:
if found == "true":
return True
else:
return False
def get_list(repo="hbb1.oscwii.org"):
print("Getting list of all packages from " + repo + "..")
with Halo(text="Getting list..", color="yellow", text_color="yellow"):
try:
u = requests.get("https://" + repo + "/metadata.json")
except requests.exceptions.SSLError:
u = requests.get("http://" + repo + "/metadata.json")
try:
data = json.loads(u.content)
except json.decoder.JSONDecodeError:
print("[Error P:001:2] Could not parse list from metadata JSON.")
exit(1)
return data
def list(repo="hbb1.oscwii.org"):
try:
u = requests.get("https://" + repo + "/metadata.json")
except requests.exceptions.SSLError:
u = requests.get("http://" + repo + "/metadata.json")
applist = []
data = json.loads(u.content)
for key in data.keys():
applist.append(key)
return applist
def repository_list(repo="hbb1.oscwii.org"):
print("Getting raw list of all repositories from " + repo + "..\n\n")
with Halo(text="Loading Secondary Repositories..", color="yellow", text_color="yellow"):
u = requests.get("https://" + repo + "/hbb/repo_list.txt").text
print(u)
def dl_list(file, display="False", repo="hbb1.oscwii.org"):
for line in open(file): # if anyone has any idea how to make this less hacky then please help
try:
line = line.rstrip("\n\r")
except Exception:
pass
try:
line = line.rstrip("\n")
except Exception:
pass
if line is "":
pass
else:
if display is True:
print(line)
else:
if query(term=line, repo=repo) is True:
metadata.get(app_name=line, type="default", repo=repo)
download.get(app_name=line, repo=repo)