-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_init.py
59 lines (48 loc) · 2.77 KB
/
db_init.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
from device_model import clear_data, initializeDB
import requests
import itertools
import operator
def initDB():
# Clearing Device table
clear_data()
# Gets the new set of devices from API
all_devices_api = requests.get("https://api.ipsw.me/v4/devices").json()
# Re-initializing DB
all_devices = [[x['name'], x['identifier'], all_devices_api.index(x)]
for x in all_devices_api if "iBridge" not in x["name"]
and "Developer Transition Kit" not in x["name"]
and "Apple Virtual Machine 1" not in x["name"]]
# Name, ID, URL, FW Version
all_iPhones = [[x, requests.get(
"https://api.ipsw.me/v4/device/{}?type=ipsw".format(x[1])).json()['firmwares'][0]['url'], requests.get(
"https://api.ipsw.me/v4/device/{}?type=ipsw".format(x[1])).json()['firmwares'][0]['version'], x[2]]
for x in all_devices if "iPhone" in x[0]]
filterFunction(all_iPhones)
all_iPads = [[x, requests.get(
"https://api.ipsw.me/v4/device/{}?type=ipsw".format(x[1])).json()['firmwares'][0]['url'], requests.get(
"https://api.ipsw.me/v4/device/{}?type=ipsw".format(x[1])).json()['firmwares'][0]['version'], x[2]]
for x in all_devices if "iPad" in x[0]]
filterFunction(all_iPads)
all_macs = [[x, requests.get(
"https://api.ipsw.me/v4/device/{}?type=ipsw".format(x[1])).json()['firmwares'][0]['url'], requests.get(
"https://api.ipsw.me/v4/device/{}?type=ipsw".format(x[1])).json()['firmwares'][0]['version'], x[2]]
for x in all_devices if "Mac" in x[0]]
filterFunction(all_macs)
all_ipods = [[x, requests.get(
"https://api.ipsw.me/v4/device/{}?type=ipsw".format(x[1])).json()['firmwares'][0]['url'], requests.get(
"https://api.ipsw.me/v4/device/{}?type=ipsw".format(x[1])).json()['firmwares'][0]['version'], x[2]]
for x in all_devices if "iPod" in x[0]]
filterFunction(all_ipods)
all_watches = [[x, requests.get("https://api.ipsw.me/v4/device/{}?type=ota".format(x[1])).json()['firmwares'][0]['url'], requests.get(
"https://api.ipsw.me/v4/device/{}?type=ota".format(x[1])).json()['firmwares'][0]['version'], x[2]]
for x in all_devices if "Watch" in x[0]]
filterFunction(all_watches)
def filterFunction(device_list):
wordsToClean = ["(GSM)", "(Global)", "(WiFi)", "(Cellular)"]
key_func = lambda x: x[1]
group = itertools.groupby(sorted(device_list, key=key_func), key=key_func)
to_clean = [[key, [[x[0][0], x[2], x[3]] for x in list(group)]] for key,group in group]
cleaned = sorted([[x[0], '/'.join(sorted(set(' '.join(x for x in y[0].split(' ') if x not in wordsToClean)
for y in x[1]))), x[1][0][1], x[1][0][2]] for x in to_clean], key=operator.itemgetter(3))
initializeDB(cleaned)
return cleaned