-
-
Notifications
You must be signed in to change notification settings - Fork 416
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
Cria spider para Duque de Caxias RJ no padrão atual do projeto #1333
Open
slfabio
wants to merge
1
commit into
okfn-brasil:main
Choose a base branch
from
slfabio:rj-duque-caxias
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import re | ||
from datetime import date, datetime | ||
|
||
from scrapy import Request | ||
|
||
from gazette.items import Gazette | ||
from gazette.spiders.base import BaseGazetteSpider | ||
from gazette.utils import date_from_text_with_fuzzy_match | ||
|
||
|
||
class RjDuqueDeCaxiasSpider(BaseGazetteSpider): | ||
name = "rj_duque_de_caxias" | ||
TERRITORY_ID = "3301702" | ||
allowed_domains = ["duquedecaxias.rj.gov.br"] | ||
start_date = date(2017, 1, 2) | ||
|
||
def start_requests(self): | ||
current_year = datetime.today().year | ||
for year in range(self.start_date.year, self.end_date.year + 1): | ||
if year == current_year: | ||
yield Request( | ||
"https://duquedecaxias.rj.gov.br/portal/boletim-oficial.html" | ||
) | ||
else: | ||
yield Request(f"https://duquedecaxias.rj.gov.br/portal/{year}.html") | ||
|
||
def parse(self, response): | ||
pdf_divs = response.xpath( | ||
"//i[contains(@class, 'fa-file-pdf')]/ancestor::div[1]" | ||
) | ||
# use descending order to reduce iterations in the daily crawl | ||
for pdf_div in pdf_divs[::-1]: | ||
raw_gazette_date = pdf_div.xpath("./preceding-sibling::div[1]/text()").get() | ||
gazette_date = date_from_text_with_fuzzy_match(raw_gazette_date) | ||
if not gazette_date or gazette_date > self.end_date: | ||
continue | ||
if gazette_date < self.start_date: | ||
return | ||
|
||
raw_gazette_edtion = pdf_div.xpath("./preceding-sibling::div[2]/text()") | ||
is_extra_edition = bool( | ||
re.search(r"extra|esp", raw_gazette_edtion.get(), re.IGNORECASE) | ||
) | ||
edition_number = ( | ||
None if is_extra_edition else raw_gazette_edtion.re_first(r"\d+") | ||
) | ||
|
||
gazette_url = response.urljoin(pdf_div.xpath(".//a/@href").get()) | ||
|
||
yield Gazette( | ||
date=gazette_date, | ||
edition_number=edition_number, | ||
is_extra_edition=is_extra_edition, | ||
file_urls=[gazette_url], | ||
power="executive_legislative", | ||
) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Todas as novas bibliotecas precisam ser adicionadas no
requirements.in
para que outros dev tenham acesso.Inclusive a que mencionou na descrição:
python-Levenshtein
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alterações realizadas nos arquivos de requirements.