-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_mongodb_data.py
72 lines (41 loc) · 1.38 KB
/
export_mongodb_data.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# coding: utf-8
# In[1]:
#importa bibliotecas
import os
import pymongo
from pymongo import MongoClient
import dns
import json
# In[2]:
client = MongoClient("mongodb+srv://teste_dados_leitura:[email protected]/myFirstDatabase?retryWrites=true&w=majority")
db = client.teste_dados
collection = db.multas_2020
# In[3]:
collection.find()
# In[5]:
collection.replace("[]", "Sem informação")
# In[10]:
# carga dos dados do banco no arquivo json
with open('multas.json', 'a') as f:
data = list()
for item in collection.find():
data.append(item)
f.write(json.dumps(data, default=str))
# In[11]:
# substitui valores inválidos
with open('multas.json', 'r') as file:
json_data = json.load(file)
for item in json_data:
if item['_id'] in ["60ab8f18ef5d383ce8403dfa","60ab8f18ef5d383ce8403e9b"]:
item['amparo_legal'] = "Resolução ANTT Nº 233 DE 25/06/2003 Art. 1º, inciso I, alínea a "
item['escopo_autuacao'] = "Transporte de passageiros"
if item['mes'] in ["JANeIRO","JaNEIRO"]:
item['mes'] = "JANEIRO"
if item['uf'] in ["Es"]:
item['uf'] = "ES"
if item['uf'] in ["Mg"]:
item['uf'] = "MG"
with open('multas.json', 'w') as file:
json.dump(json_data, file, indent=2)
# In[ ]: