|
1 | | -import jstyleson |
2 | 1 | import json |
3 | 2 | import glob |
4 | 3 | import os |
|
10 | 9 | for filename in glob.glob(os.path.join('.', '*.json')): |
11 | 10 | if filename not in ignore: |
12 | 11 | print(f"Opening: {filename}") |
13 | | - |
14 | | - with open(filename, "r") as file: |
15 | | - filecontent = file.read() |
16 | | - |
17 | | - try: |
18 | | - modlist = jstyleson.loads(filecontent) |
19 | | - except Exception as err: |
20 | | - print(f"❌ Error reading JSON file {filename}: {err}") |
21 | | - sys.exit(os.EX_SOFTWARE) |
22 | | - |
| 12 | + filecontent = open(filename, "r").read() |
| 13 | + modlist = json.loads(filecontent) |
23 | 14 | for mod, data in modlist.items(): |
24 | 15 | url = data["download"].replace(" ", "%20") |
25 | 16 | print(f"Download {mod}: {url}") |
26 | | - |
27 | 17 | try: |
28 | 18 | response = urllib.request.urlopen(url) |
29 | | - filecontent = response.read() |
30 | | - print(f"✅ Download successful") |
31 | | - except Exception as err: |
32 | | - print(f"❌ Download failed: {err}") |
| 19 | + except: |
| 20 | + print("Error: download failed!") |
33 | 21 | sys.exit(os.EX_SOFTWARE) |
34 | | - |
35 | | - filesize = round(len(filecontent) / 1024 / 1024, 3) |
36 | | - print(f"Size: {filesize} MB") |
| 22 | + filesize = round(len(response.read()) / 1024 / 1024, 3) |
| 23 | + print(f"Size: {filesize}") |
37 | 24 | data["downloadSize"] = filesize |
38 | 25 |
|
39 | 26 | resultcontent = json.dumps(modlist, indent='\t', separators=(',', ' : ')) + "\n" |
40 | 27 |
|
41 | 28 | if filecontent != resultcontent: |
42 | | - with open(filename, "w") as file: |
43 | | - file.write(resultcontent) |
| 29 | + open(filename, "w").write(resultcontent) |
44 | 30 |
|
45 | 31 | sys.exit(os.EX_OK) |
0 commit comments