-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from UnB-KnEDLe/dev
Update Dowloader
- Loading branch information
Showing
8 changed files
with
167 additions
and
118 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import json | ||
from _pytest.python_api import raises | ||
import requests | ||
import os | ||
|
||
|
||
url_ = 'https://dodf.df.gov.br/listar?' | ||
downl = 'https://dodf.df.gov.br/index/visualizar-arquivo/?pasta=' | ||
|
||
|
||
#req1 returns list with available months for the given year | ||
def req1(year): | ||
url1 = url_+f'dir={str(year)}' | ||
return url1 | ||
|
||
#req2 returns list with available DODFs for the given month | ||
def req2(url1, month): | ||
if("_" in month): | ||
url2 = url1 + '/' + month | ||
req2 = requests.get(url2) | ||
content2 = json.loads(req2.content) | ||
dodfs = list(content2['data'].items()) | ||
return(url2, dodfs) | ||
else: | ||
raise ValueError("month parameter format is wrong") | ||
|
||
|
||
#req3 returns all pdfs from the selected DODF | ||
def req3(url2, dodf): | ||
url3 = url2+"/"+dodf.replace(" ","%20") | ||
req3 = requests.get(url3) | ||
content3 = json.loads(req3.content) | ||
pdfs = content3['data'] | ||
return(url3, pdfs) | ||
|
||
|
||
#Check for DODFs on the selected date | ||
def check_date(year, month): | ||
if("_" in month): | ||
url1 = url_+f'dir={year}/{month}' | ||
req = requests.get(url1) | ||
content = json.loads(req.content) | ||
if('data' in content.keys()): | ||
if(len(content["data"]) > 0): | ||
return True | ||
else: | ||
return False | ||
else: | ||
return False | ||
else: | ||
raise ValueError("month parameter format is wrong") | ||
|
||
#Generates download url | ||
def get_downloads(year, month): | ||
if("_" in month): | ||
url1 = req1(year) | ||
url2, dodfs = req2(url1,month) | ||
_links = {} | ||
|
||
#Lista de DODFS: | ||
for dodf in dodfs: | ||
url3, pdfs = req3(url2,dodf[1]) | ||
dodf_name = dodf[1] | ||
_pdfs = [] | ||
for pdf in pdfs: | ||
index1 = url3.find(year) | ||
dir_ = (url3[index1:]).replace("/","|")+'|'+'&arquivo=' | ||
index2 = pdf.rfind("/") | ||
arq_ = pdf[index2+1:].replace(" ","%20") | ||
link_download = downl+dir_+arq_ | ||
_pdfs.append(link_download) | ||
_links[dodf_name] = _pdfs | ||
|
||
return(_links) | ||
else: | ||
raise ValueError("month parameter format is wrong") | ||
|
||
|
||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
,nome,matricula,cargo_efetivo,classe,padrao,orgao_cedente,orgao_cessionario,onus,fundamento legal,processo_SEI,vigencia,matricula_SIAPE,cargo_orgao_cessionario,simbolo,hierarquia_lotacao | ||
0,ROBERT WAGNER DE SANTANA,1.430.783-9,,,,,,ONUS FINANCEIRO: orgao cedente.,,04019-00000669/2019-17.,,, com alicerce no art. 2o,, | ||
1,JULIO CESAR MENEGOTTO,74.682-7,,,,,,"onus para o orgao | ||
0,SADI PERES MARTINS,79.206-3,,,,,,"ONUS FINANCEIRO: orgao cessionario, com ressarcimento mensal a origem.",,-,,, resolve: SUSPENDER,, | ||
1,ARLETE OLIVEIRA SANTOS GONDAR,124.604-6,,,,,,ONUS FINANCEIRO: orgao cedente.,,00138-00007294/2019-45,,, com alicerce no art. 2o,, | ||
2,ROBERT WAGNER DE SANTANA,1.430.783-9,,,,,,ONUS FINANCEIRO: orgao cedente.,,04019-00000669/2019-17.,,, com alicerce no art. 2o,, | ||
3,JULIO CESAR MENEGOTTO,74.682-7,,,,,,"onus para o orgao | ||
de origem, conforme Decisao da Diretoria Executiva, exarada pela Sessao no 4.",,00112-00037276/2019-21.,,, usando das atribuicoes conferidas pelo Art. 25,, | ||
2,ARLETE OLIVEIRA SANTOS GONDAR,124.604-6,,,,,,ONUS FINANCEIRO: orgao cedente.,,00138-00007294/2019-45,,, com alicerce no art. 2o,, | ||
3,SADI PERES MARTINS,79.206-3,,,,,,"ONUS FINANCEIRO: orgao cessionario, com ressarcimento mensal a origem.",,-,,, resolve: SUSPENDER,, |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
,tipo_ato,tipo_documento,numero_documento,data_documento,numero_dodf,data_dodf,pagina_dodf,nome,matricula,matricula_SIAPE,cargo_efetivo,classe,padrao,quadro,orgao,processo_SEI,tipo_edicao | ||
0,Atos tornados sem efeito - aposentadoria,,,05 de fevereiro de 1990,248,"29 de | ||
0,Atos tornados sem efeito - aposentadoria,Ordem de Servico,,03 de dezembro de 2019,04,04 de dezembro de 2019,," FRANCINEIDE | ||
DANIEL DE LIMA",66.260-7,, no Cargo de Professor de Educacao Basica,,,,,00040-00024368/2019-32,normal | ||
1,Atos tornados sem efeito - aposentadoria,,,26 de fevereiro de 2019,42,28 de fevereiro 2019, 29,GENI TEREZINHA SPIES DA SILVEIRA,30735-1,, totalizando 731 dias,,,,,00401.00003406/2019-59,normal | ||
2,Atos tornados sem efeito - aposentadoria,,,,137,19/07/2017,. 42, DELFINO BERNARDES RABELO,100.652-5. ,,,,,,,0070-001865/2016,normal | ||
3,Atos tornados sem efeito - aposentadoria,,,05 de fevereiro de 1990,248,"29 de | ||
dezembro de 2017", 39.,"MARCO | ||
ANTONIO CATTANI FRANCA","129661-2,",, 129.661-2,,,,,271.000.680/2017,normal | ||
1,Atos tornados sem efeito - aposentadoria,,,,137,19/07/2017,. 42, DELFINO BERNARDES RABELO,100.652-5. ,,,,,,,0070-001865/2016,normal | ||
2,Atos tornados sem efeito - aposentadoria,Ordem de Servico,,03 de dezembro de 2019,04,04 de dezembro de 2019,," FRANCINEIDE | ||
DANIEL DE LIMA",66.260-7,, no Cargo de Professor de Educacao Basica,,,,,00040-00024368/2019-32,normal | ||
3,Atos tornados sem efeito - aposentadoria,,,26 de fevereiro de 2019,42,28 de fevereiro 2019, 29,GENI TEREZINHA SPIES DA SILVEIRA,30735-1,, totalizando 731 dias,,,,,00401.00003406/2019-59,normal |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pytest | ||
from dodfminer.downloader.helper import req1, req2, req3, get_downloads, check_date | ||
|
||
|
||
def test_req1(): | ||
assert req1(2017) == 'https://dodf.df.gov.br/listar?dir=2017' | ||
|
||
def test_req2(): | ||
assert type(req2('https://dodf.df.gov.br/listar?dir=2017', '01_Janeiro')) == tuple | ||
|
||
def test_req2_2(): | ||
with pytest.raises(ValueError): | ||
assert (req2('https://dodf.df.gov.br/listar?dir=2017', 'Janeiro')) | ||
|
||
def test_req3(): | ||
assert type(req3('https://dodf.df.gov.br/listar?dir=2017', 'DODF 023 31-01-2006')) == tuple | ||
|
||
def test_get_downloads(): | ||
assert type(get_downloads('2017', '01_Janeiro')) == dict | ||
|
||
def test_get_downloads_2(): | ||
with pytest.raises(ValueError): | ||
assert (get_downloads('2017', 'Janeiro')) | ||
|
||
def test_check_date(): | ||
assert type(check_date('2017', '01_Janeiro')) == bool | ||
|
||
def test_check_date_2(): | ||
with pytest.raises(ValueError): | ||
assert (check_date('2017', 'Janeiro')) |
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