forked from PaulJenkin/PS4RaspberryPi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdatetrainer.py
32 lines (25 loc) · 998 Bytes
/
updatetrainer.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
#!/usr/bin/env python3
import urllib.request, json, os
from multiprocessing.pool import ThreadPool
savepath = "/usr/html/Resources/OffTrainer/"
gameurl = []
def download(url):
file_name_start_pos = url.rfind("/") + 1
file_name = url[file_name_start_pos:]
try:
if file_name.split('.')[-1] != 'jpg' or not os.path.isfile(savepath + file_name):
urllib.request.urlretrieve(url, savepath + file_name)
except:
pass
with urllib.request.urlopen("http://ps4trainer.com/Trainer/list.json") as url:
data_json = url.read().decode('utf-8-sig')
data = json.loads(data_json)
f = open(savepath + "list.json", "w")
f.write(data_json.replace("/games", ""))
f.close()
for game in data['games']:
gameurl.append(game['url'].replace(".", "http://ps4trainer.com/Trainer", 1))
gameurl.append("http://ps4trainer.com/Trainer/img/" + game['title'] + ".jpg")
results = ThreadPool(8).imap_unordered(download, gameurl)
for r in results:
pass