Created
August 31, 2016 17:15
-
-
Save Irio/24282ae5dadb551c75cec5dc48e811a5 to your computer and use it in GitHub Desktop.
[Serenata de Amor] Deputy paying for his own campaign
This file contains 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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Deputy paying for his own campaign" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import json\n", | |
"import numpy as np\n", | |
"import pandas as pd\n", | |
"from urllib.request import urlopen\n", | |
"\n", | |
"CNPJ = '20574089000107'\n", | |
"\n", | |
"def document_url(record):\n", | |
" return 'http://www.camara.gov.br/cota-parlamentar/documentos/publ/%s/%s/%s.pdf' % \\\n", | |
" (record['applicant_id'], record['year'], record['document_id'])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"current_year = pd.read_csv('../data/2016-08-08-current-year.xz',\n", | |
" parse_dates=[16],\n", | |
" low_memory=False,\n", | |
" dtype={'document_id': np.str,\n", | |
" 'congressperson_id': np.str,\n", | |
" 'congressperson_document': np.str,\n", | |
" 'term_id': np.str,\n", | |
" 'cnpj_cpf': np.str,\n", | |
" 'reimbursement_number': np.str})\n", | |
"last_year = pd.read_csv('../data/2016-08-08-last-year.xz',\n", | |
" parse_dates=[16],\n", | |
" low_memory=False,\n", | |
" dtype={'document_id': np.str,\n", | |
" 'congressperson_id': np.str,\n", | |
" 'congressperson_document': np.str,\n", | |
" 'term_id': np.str,\n", | |
" 'cnpj_cpf': np.str,\n", | |
" 'reimbursement_number': np.str})\n", | |
"previous_years = pd.read_csv('../data/2016-08-08-previous-years.xz',\n", | |
" parse_dates=[16],\n", | |
" low_memory=False,\n", | |
" dtype={'document_id': np.str,\n", | |
" 'congressperson_id': np.str,\n", | |
" 'congressperson_document': np.str,\n", | |
" 'term_id': np.str,\n", | |
" 'cnpj_cpf': np.str,\n", | |
" 'reimbursement_number': np.str})\n", | |
"data = pd.concat([current_year, last_year, previous_years])\n", | |
"del(current_year)\n", | |
"del(last_year)\n", | |
"del(previous_years)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(2072729, 29)" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"data.shape" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"1" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"records = data[data['cnpj_cpf'] == CNPJ]\n", | |
"len(records)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"document_id 5621548\n", | |
"congressperson_name ODELMO LEÃO\n", | |
"congressperson_id 74752\n", | |
"congressperson_document 248\n", | |
"term 2015\n", | |
"state MG\n", | |
"party PP\n", | |
"term_id 55\n", | |
"subquota_number 11\n", | |
"subquota_description Postal services\n", | |
"subquota_group_id 0\n", | |
"subquota_group_description NaN\n", | |
"supplier Magnino Franquia e Serviços Ltda\n", | |
"cnpj_cpf 20574089000107\n", | |
"document_number 29022\n", | |
"document_type 1\n", | |
"issue_date 2015-02-26 00:00:00\n", | |
"document_value 190.05\n", | |
"remark_value 0\n", | |
"net_value 190.05\n", | |
"month 2\n", | |
"year 2015\n", | |
"installment 0\n", | |
"passenger NaN\n", | |
"leg_of_the_trip NaN\n", | |
"batch_number 1172687\n", | |
"reimbursement_number 4953\n", | |
"reimbursement_value NaN\n", | |
"applicant_id 705\n", | |
"Name: 269177, dtype: object" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"record = records.iloc[0]\n", | |
"record" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"http://www.camara.gov.br/cota-parlamentar/documentos/publ/705/2015/5621548.pdf\n" | |
] | |
} | |
], | |
"source": [ | |
"print(document_url(record))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Backup: https://cl.ly/0c0h3E2N132e" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'abertura': '06/07/2014',\n", | |
" 'atividade_principal': [{'code': '00.00-0-00', 'text': '********'}],\n", | |
" 'atividades_secundarias': [{'code': '00.00-0-00', 'text': 'Não informada'}],\n", | |
" 'bairro': '',\n", | |
" 'cep': '',\n", | |
" 'cnpj': '20.574.089/0001-07',\n", | |
" 'complemento': '',\n", | |
" 'data_situacao': '31/12/2014',\n", | |
" 'data_situacao_especial': '',\n", | |
" 'efr': '',\n", | |
" 'email': 'junqueiraanapaula@gmail.com',\n", | |
" 'fantasia': '',\n", | |
" 'logradouro': '',\n", | |
" 'motivo_situacao': 'EXTINCAO P/ ENC LIQ VOLUNTARIA',\n", | |
" 'municipio': '',\n", | |
" 'natureza_juridica': '409-0 - CANDIDATO A CARGO POLITICO ELETIVO',\n", | |
" 'nome': 'ELEICAO 2014 ODELMO LEAO CARNEIRO SOBRINHO DEPUTADO FEDERAL',\n", | |
" 'numero': '',\n", | |
" 'situacao': 'BAIXADA',\n", | |
" 'situacao_especial': '',\n", | |
" 'status': 'OK',\n", | |
" 'telefone': '(0) 0-',\n", | |
" 'tipo': 'MATRIZ',\n", | |
" 'uf': '',\n", | |
" 'ultima_atualizacao': '2016-07-19T20:59:31.290Z'}" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"url = 'http://receitaws.com.br/v1/cnpj/%s' % CNPJ\n", | |
"json_contents = urlopen(url).read().decode('utf-8')\n", | |
"json.loads(json_contents)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python3", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.5.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment