-
Notifications
You must be signed in to change notification settings - Fork 6
/
baixar_bus.py
67 lines (64 loc) · 1.8 KB
/
baixar_bus.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
import json
import sys
ufs = [
'ac',
'al',
'ap',
'am',
'ba',
'ce',
'es',
'go',
'ma',
'mt',
'ms',
'mg',
'pa',
'pb',
'pr',
'pe',
'pi',
'rj',
'rn',
'rs',
'ro',
'rr',
'sc',
'sp',
'se',
'to',
'df',
'zz',
]
exts = ['bu', 'rdv', 'logjez', 'vscmr', 'imgbu']
def main(argv):
if len(argv) < 1:
print(f'ERRO: parametro obrigatorio {exts}')
exit(1)
ext = argv[0]
if ext not in exts:
print(f'ERRO: {ext} nao eh um tipo conhecido {exts}')
exit(2)
for uf in ufs:
with open(f'secoes/secoes_{uf}.json') as f:
d = json.load(f)
for iabr in d['abr']:
for mu in iabr['mu']:
codmun = mu['cd']
for zon in mu['zon']:
codzon = zon['cd']
for sec in zon['sec']:
codsec = sec['ns']
hashfilename = f'hashes/hash-{uf}-m{codmun}-z{codzon}-s{codsec}.json'
try:
with open(hashfilename) as hf:
dh = json.load(hf)
_hash = dh['hashes'][0]['hash']
url = f'https://resultados.tse.jus.br/oficial/ele2022/arquivo-urna/406/dados/{uf}/{codmun}/{codzon}/{codsec}/{_hash}/o00406-{codmun}{codzon}{codsec}.{ext}'
filename = f'{uf}-{codmun}-{codzon}-{codsec}.{ext}'
print(f'wget {url} -O result/{filename}')
except:
print(f'deu ruim {hashfilename}')
raise
if __name__ == '__main__':
main(sys.argv[1:])