File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 3
3
import os
4
4
import sys
5
5
import urllib .request
6
+ from io import StringIO
6
7
7
8
from ignore_json import ignore
8
9
11
12
for filename in glob .glob (os .path .join ('.' , '*.json' )):
12
13
if filename not in ignore :
13
14
print (f"Opening: { filename } " )
14
- filecontent = open (filename , "r" ).read ()
15
-
15
+
16
+ with open (filename , "r" ) as file :
17
+ filecontent = file .read ()
18
+
16
19
try :
17
20
modlist = jstyleson .loads (filecontent )
18
21
except Exception as err :
23
26
for mod , data in modlist .items ():
24
27
url = data ["mod" ].replace (" " , "%20" )
25
28
print (f"{ mod } : { url } " )
29
+
26
30
try :
27
31
response = urllib .request .urlopen (url )
28
32
print (f"✅ Download successful" )
31
35
print (f"❌ Download failed: { err } " )
32
36
continue
33
37
34
- filecontent = response .read ()
35
-
36
38
try :
37
- jstyleson .loads (filecontent )
39
+ filecontent = response .read ().decode ("utf-8" )
40
+ jstyleson .load (StringIO (filecontent ))
38
41
print (f"✅ JSON valid" )
39
42
except Exception as err :
40
43
error = True
41
44
print (f"❌ JSON invalid:" )
42
45
print (str (err ))
43
46
continue
47
+
44
48
if error :
45
49
sys .exit (os .EX_SOFTWARE )
46
50
else :
You can’t perform that action at this time.
0 commit comments