Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adiciona novo raspador para Florianópolis-SC e atualiza antigo #1349

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class ScFlorianopolisSpider(BaseGazetteSpider):
name = "sc_florianopolis"
name = "sc_florianopolis_2009"
TERRITORY_ID = "4205407"
start_date = date(2009, 6, 1)

Expand All @@ -24,7 +24,7 @@ def start_requests(self):
for year, month in periods_of_interest:
data = dict(ano=str(year), mes=str(month), passo="1", enviar="")
yield FormRequest(
"https://www.pmf.sc.gov.br/governo/index.php?pagina=govdiariooficial",
"https://www.pmf.sc.gov.br/governo/index.php?pagina=govdiarioantigo",
formdata=data,
)

Expand Down
49 changes: 49 additions & 0 deletions data_collection/gazette/spiders/sc/sc_florianopolis_2024.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from datetime import date, datetime

from scrapy import FormRequest

from gazette.items import Gazette
from gazette.spiders.base import BaseGazetteSpider


class ScFlorianopolisSpider(BaseGazetteSpider):
name = "sc_florianopolis_2024"
TERRITORY_ID = "4205407"
start_date = date(2024, 8, 5)
allowed_domains = ["edicao.dom.sc.gov.br"]

def _requests(self, page):
formdata = {
"Edicao[cod_municipio]": "146",
"Edicao_page": str(page),
"r": "site/edicoes",
}
return FormRequest(
url="https://edicao.dom.sc.gov.br/?",
method="GET",
formdata=formdata,
callback=self.parse_pagination,
cb_kwargs={"page": page},
)

def start_requests(self):
yield self._requests(1)

def parse_pagination(self, response, page):
for item in response.css("tbody tr"):
edition_number = item.css("td::text")[1].get()
edition_url = item.css("td a")[1].attrib["href"]
raw_date = item.css("td::text")[2].get()
edition_date = datetime.strptime(raw_date, "%d/%m/%Y").date()

if self.start_date <= edition_date <= self.end_date:
yield Gazette(
date=edition_date,
edition_number=edition_number,
is_extra_edition=False,
power="executive_legislative",
file_urls=[edition_url],
)

if edition_date > self.start_date:
yield self._requests(page + 1)
Loading