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

Am associacao municipal devolpment #1315

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
39 changes: 35 additions & 4 deletions data_collection/gazette/spiders/am/am_associacao_municipios.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
from gazette.spiders.base.sigpub import BaseSigpubSpider
import datetime as dt

import scrapy
from dateutil import rrule

class AmAssociacaoMunicipiosSpider(BaseSigpubSpider):
name = "am_associacao_municipios"
from gazette.items import Gazette
from gazette.spiders.base import BaseGazetteSpider


class AmAssociacaoMunicipiosSpider(BaseGazetteSpider):
TERRITORY_ID = "1300000"
CALENDAR_URL = "https://www.diariomunicipal.com.br/aam"
name = "am_associacao_municipios"
allowed_domains = ["https://diariomunicipalaam.org.br/"]
download_url = "https://diariomunicipalaam.org.br/visualizar-publicacao/{}"
start_date = dt.date(2009, 10, 19) # primeira edição encontrada
end_date = dt.date.today()

def start_requests(self):
for date in rrule.rrule(
rrule.DAILY, dtstart=self.start_date, until=self.end_date
):
formatted_date = date.strftime("%Y%m%d") # Formato YYYYMMDD
url = self.download_url.format(formatted_date)
yield scrapy.Request(
url,
method="HEAD",
callback=self.parse_valid_gazette_file,
cb_kwargs={"gazette_date": date.date()},
)

def parse_valid_gazette_file(self, response, gazette_date):
if response.status == 200:
yield Gazette(
date=gazette_date,
file_urls=[response.url],
is_extra_edition=False,
power="executive",
)
Loading