-
Notifications
You must be signed in to change notification settings - Fork 0
/
TinydbDownloader.py
62 lines (55 loc) · 1.99 KB
/
TinydbDownloader.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
import requests
import json
import re
base_url = "https://tinydb.eiphax.tech/api"
apps = requests.get(f"{base_url}/apps").text
apps_json = json.loads(apps)
def list_all_apps():
for app in apps_json:
if app["cia"]:
id = app["id"]
name = app["name"]
headline = app["headline"]
last_updated = str(app["cia"][-1]["mtime"])[0:9]
print(f"ID {id}: {name} | {headline} | Last updated: {last_updated}")
else:
pass
def search_for_app(search):
for app in apps_json:
if re.search(search, app["name"], re.IGNORECASE):
if app["cia"]:
id = app["id"]
name = app["name"]
headline = app["headline"]
print(f"ID {id}: {name} | {headline}")
else:
pass
else:
pass
def download():
ids = input("Choose app id(s) to download in a comma separated list or (Q)uit:").replace(" ", "").split(",")
for id in ids:
if id.isnumeric():
try:
download_url = json.loads(requests.get(f"{base_url}/apps?app_id={id}").text)[0]["cia"][-1]["download_url"]
cia_file = requests.get(download_url)
open(download_url.split("/")[-1], "wb").write(cia_file.content)
except IndexError:
print("Invalid id: {}".format(id))
else:
print("Invalid id: {}".format(id))
def main():
while True:
choice = input("What do you want to do? (L)ist all apps, (S)earch for a app or (Q)uit the program:")
if choice.lower() == "l":
list_all_apps()
download()
elif choice.lower() == "s":
search_for_app(input("Enter a string to search for:"))
download()
elif choice.lower() == "q":
print("Quitting")
quit()
else:
print("Invalid choice, try again.")
main()