Skip to content

Commit 6c16569

Browse files
authored
Update validate_mod_json.py
1 parent 68ad655 commit 6c16569

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

.github/validate_mod_json.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import sys
55
import urllib.request
6+
from io import StringIO
67

78
from ignore_json import ignore
89

@@ -11,8 +12,10 @@
1112
for filename in glob.glob(os.path.join('.', '*.json')):
1213
if filename not in ignore:
1314
print(f"Opening: {filename}")
14-
filecontent = open(filename, "r").read()
15-
15+
16+
with open(filename, "r") as file:
17+
filecontent = file.read()
18+
1619
try:
1720
modlist = jstyleson.loads(filecontent)
1821
except Exception as err:
@@ -23,6 +26,7 @@
2326
for mod, data in modlist.items():
2427
url = data["mod"].replace(" ", "%20")
2528
print(f"{mod}: {url}")
29+
2630
try:
2731
response = urllib.request.urlopen(url)
2832
print(f"✅ Download successful")
@@ -31,16 +35,16 @@
3135
print(f"❌ Download failed: {err}")
3236
continue
3337

34-
filecontent = response.read()
35-
3638
try:
37-
jstyleson.loads(filecontent)
39+
filecontent = response.read().decode("utf-8")
40+
jstyleson.load(StringIO(filecontent))
3841
print(f"✅ JSON valid")
3942
except Exception as err:
4043
error = True
4144
print(f"❌ JSON invalid:")
4245
print(str(err))
4346
continue
47+
4448
if error:
4549
sys.exit(os.EX_SOFTWARE)
4650
else:

0 commit comments

Comments
 (0)