Advertisement
Fer22f

Processamento da Planilha

Nov 2nd, 2020
2,577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. import json
  2. import csv
  3.  
  4. with open('teams.json') as f:
  5.     teams = json.load(f)
  6.  
  7. SEDE = {
  8.     'Rio de Janeiro': 'RJ',
  9.     'Rio Grande do Sul': 'RS',
  10.     'Rio Grande do Norte': 'RN',
  11.     'Paraiba': 'PB',
  12.     'Distrito Federal': 'DF',
  13.     'Minas Gerais': 'MG',
  14.     'Mato Grosso do Sul': 'MS',
  15.     'Mato Grosso': 'MT',
  16.     'Parana': 'PR',
  17.     'Ceara': 'CE',
  18.     'Amapa': 'AP',
  19.     'Maranhao': 'MA',
  20.     'Sao Paulo': 'SP',
  21.     'Alagoas': 'AL',
  22.     'Santa Catarina': 'SC',
  23.     'Bahia': 'BA',
  24.     'Amazonas': 'AM',
  25.     'Para': 'PA',
  26.     'Rondonia': 'RO',
  27.     'Piaui': 'PI',
  28.     'Acre': 'AC',
  29.     'Pernambuco': 'PE',
  30.     'Sergipe': 'SE',
  31.     'Goias': 'GO',
  32.     'Roraima': 'RR',
  33.     'Espirito Santo': 'ES',
  34. }
  35.  
  36. with open('teams.csv', 'w', newline='') as f:
  37.     rows = sorted([((SEDE[team['site']['name']], team['institution'].strip(), team['name'].strip())) for team in teams])
  38.     writer = csv.writer(f)
  39.     writer.writerows(rows)
  40.  
  41. # From the spreadsheet
  42. with open('planilha.csv', newline='') as f:
  43.     rows = csv.reader(f)
  44.     rows = sorted([(row[1], row[2], row[3]) for row in rows if len(row[1]) == 2])
  45.  
  46. with open('planilha.csv', 'w', newline='') as f:
  47.     writer = csv.writer(f)
  48.     writer.writerows(rows)
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement