Skip to content
Snippets Groups Projects
Commit cb67b934 authored by Edu Trevisan's avatar Edu Trevisan
Browse files

Add script to new table

parent 777aa523
No related branches found
No related tags found
No related merge requests found
# Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
# This file is part of SMPPIR-Tables.
# SMPPIR-Tables is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# SMPPIR-Tables is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with SMPPIR-Tables. If not, see <https://www.gnu.org/licenses/>.
# Para conseguir os dados dos homicídios de jovens siga os seguintes passos:
# 1 - Acesse o tabnet em estatísticas vitais nos dados de mortalidade geral em:
# http: // tabnet.datasus.gov.br/cgi/deftohtm.exe?sim/cnv/obt10uf.def
# 2 - Selecione os seguintes filtros:
# No filtro de linha selecione "Unidade de Federação"
# Na coluna selecione "Cor/Raça"
# No conteúdo selecione "Óbitos p/Ocorrência"
# Selecione o ano desejado
# Na Causa - CID-BR-10 selecione ".110 Agressões"
# Na Faixa Etária selecione o intervalo de 15 a 29 anos(use Ctrl para selecionar os 2)
# 3 - Selecione Colunas separadas por ";" e clique em "Mostra"
# 4 - Copie o resultado descartando o "&" no folder dados em um arquivo chamado
# homicidios_jovens_201X.csv
# 5 - Execute o script homicidios_jovens.py
# 6 - O resultado está no folder dadosProcessados
import os
import csv
import sys
folder = "dados/"
fileName = "homicidios_jovens_"
year = int(input("Ano:"))
# Tentar abrir arquivo
try:
ifile = open(folder + fileName + str(year) + '.csv', 'r')
except IOError:
print('Arquivo nao encontrado: ' + folder + fileName +
str(year) + '.csv')
exit()
if not os.path.exists('dadosProcessados'):
os.makedirs('dadosProcessados')
# Se nao houve erro tratar csv
reader = csv.reader(ifile, delimiter=';')
ofile = open('dadosProcessados/' + fileName +
str(year) + '.csv', 'w')
writer = csv.writer(ofile, delimiter='|')
# Escrever header no arquivo
headers = next(reader, None)
headers.insert(0,'estado_id')
headers.append('ANO_CENSO')
writer.writerow(headers)
# Escrever linhas no arquivo com informacoes do ano
for row in reader:
row.insert(0, row[0].split()[0])
for i, string in enumerate(row):
row[i] = string.replace("-", "0")
row.append(year)
if row[0] != 'Total':
writer.writerow(row)
ifile.close()
ofile.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment