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 33import os
44import sys
55import urllib .request
6+ from io import StringIO
67
78from ignore_json import ignore
89
1112for 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 :
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" )
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+
4448if error :
4549 sys .exit (os .EX_SOFTWARE )
4650else :
You can’t perform that action at this time.
0 commit comments