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

Spider for Campo Mourão/PR #438

Closed
wants to merge 3 commits into from
Closed
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
52 changes: 52 additions & 0 deletions data_collection/gazette/spiders/pr_campo_mourao.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import datetime

from dateparser import parse

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


class PrCampoMouraoSpider(BaseGazetteSpider):
TERRITORY_ID = "4104303"
name = "pr_campo_mourao"
start_date = datetime.date(2012, 3, 2)
start_urls = ["https://campomourao.atende.net/?pg=diariooficial&pagina=1"]

def parse(self, response, page=1):

gazettes = response.xpath("//div[@class='nova_listagem ']/div[@class='linha']")
follow_next_page = False if not gazettes else True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
follow_next_page = False if not gazettes else True
follow_next_page = bool(gazettes)


for gazette in gazettes:
date = gazette.xpath(".//div[@class='data']/text()").get()
date = parse(date, languages=["pt"]).date()

if date < self.start_date:
follow_next_page = False
break

edition_type = gazette.xpath(".//div[@class='tipo']/text()").get()
edition_number = gazette.xpath(".//div[@class='titulo']/text()").get()
edition_number = edition_number.split(" ")[1]

code = gazette.xpath("//button[@data-acao='download']/@data-codigo").get()
id = gazette.xpath("//button[@data-acao='download']/@data-id").get()

is_extra = True if edition_type == "Extraordinária" else False
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
is_extra = True if edition_type == "Extraordinária" else False
is_extra = edition_type == "Extraordinária"


url = f"https://campomourao.atende.net/atende.php?rot=54002&aca=737&processo=download&codigo={code}&hash={id}"

yield Gazette(
ogecece marked this conversation as resolved.
Show resolved Hide resolved
date=date,
edition_number=edition_number,
file_urls=[url],
is_extra_edition=is_extra,
power="executive_legislative",
)

if follow_next_page:
next_page = page + 1
yield response.follow(
f"https://campomourao.atende.net/?pg=diariooficial&pagina={next_page}",
cb_kwargs={"page": next_page},
)