-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalida_dicionario.py
42 lines (37 loc) · 1.29 KB
/
valida_dicionario.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
import h2.utilities
import json
import re
with open('dicionario.json', "r") as file:
cont = 0
for line in file.readlines():
if re.search("(\".*\":\s*\".*\")",line):
if re.search("(\".*\":\s*\".*\")(?=,)*",line):
j = re.search("(\".*\":\s*\".*\")(?=,)*",line).group(0)
# j = '{' + line.replace("\n","") + '}'
j = '{' + j + '}'
try:
a = json.loads(j)
for k,v in a.items():
if k.upper() == v.upper():
print(k,"\n",v)
cont += 1
except Exception as e:
print (e)
print (j)
pass
print (cont)
with open('dicionario.json', "r") as file:
dicionario = json.loads(file.read())
file.close()
new_dicionario={}
for k,v in dicionario.items():
if k.upper() != v.upper():
new_dicionario[k]=v
try:
jdumps = json.dumps(new_dicionario,indent=4, sort_keys=True, ensure_ascii=False)
with open("dicionario_teste.json", "wb") as file:
file.write(jdumps.encode('utf-8'))
except Exception as e:
print (e)
print ( type(new_dicionario))
print (type(jdumps))