This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| from pymongo import MongoClient, UpdateOne | |
| connection_string = 'mongodb://host:port' | |
| db = MongoClient(connection_string)['camara'] | |
| legislaturas = ','.join([str(n) for n in range(52, 56)]) | |
| url = 'https://dadosabertos.camara.leg.br/api/v2/deputados/?idLegislatura={}&itens=100'.format(legislaturas) | |
| while True: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import datetime as dt | |
| import requests | |
| from pymongo import MongoClient, UpdateOne | |
| connection_string = 'mongodb://host:port' # escondendo minha connection string original, por conter usuario e senha | |
| db = MongoClient(connection_string)['camara'] | |
| legislaturas = ','.join([str(n) for n in range(52, 56)]) | |
| url = 'https://dadosabertos.camara.leg.br/api/v2/deputados/?idLegislatura={}&itens=100'.format(legislaturas) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| q = db.parlamentares.aggregate([ | |
| { | |
| '$unwind': '$mandatos' # para separar cada legislatura em diferentes documentos | |
| },{ | |
| '$group': { | |
| '_id': '$mandatos.legislatura', | |
| 'total': {'$sum': 1} | |
| } | |
| } | |
| ]) |