-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathcheckjson.py
executable file
·51 lines (47 loc) · 1.98 KB
/
checkjson.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
# coding=utf8
import re
import os
import pprint
import simplejson
import sys
counterr = 0
invalid_json_files = []
misplaced = [f for f in os.listdir('.') if re.match(r'.*\.json', f)]
if misplaced:
sys.exit ("JSON files found in root folder, misplaced?")
os.chdir(os.getcwd() + "/rmd")
json_files = [f for f in os.listdir('.') if re.match(r'.*\.json', f)]
for files in json_files:
with open(files) as json_file:
try:
countin = 0
countout = 0
djson = simplejson.load(json_file)
for rmid in djson:
countin += 1
if ("Text" in djson[rmid] and (djson[rmid]["Text"] != "")):
if ("Enabled" not in djson[rmid] or (djson[rmid]["Enabled"] == False)):
print ("%s:%s entry not enabled" % (files, rmid))
pprint.pprint(djson[rmid])
#counterr += 1
if ("[" in djson[rmid]["Text"]) and not ("]" in djson[rmid]["Text"]):
print ("%s:%s unclosed [" % (files, rmid))
pprint.pprint(djson[rmid])
counterr += 1
if ("]" in djson[rmid]["Text"]) and not ("[" in djson[rmid]["Text"]):
print ("%s:%s unclosed ]" % (files, rmid))
pprint.pprint(djson[rmid])
counterr += 1
if ("Story" in files and "Summaries" not in files):
for strs in djson[rmid]["Text"].split('\n'):
if (len(strs) > 110):
print ("%s:%s too long" % (files, rmid))
#pprint.pprint(djson[rmid])
#counterr += 1
except ValueError as e:
print("%s: %s") % (files, e)
invalid_json_files.append(files)
counterr += len(invalid_json_files)
if counterr != 0:
sys.exit("=============\nJSON files with issues: %d" % counterr)