-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
Add ValeGazetteSpider e alguns municípios que a utilizam #1127
Open
vcoelh
wants to merge
6
commits into
okfn-brasil:main
Choose a base branch
from
vcoelh:ValeGazetteSpider
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 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
272822d
add base_vale
vcoelh 38e6320
add to_pium
vcoelh acac27d
add to_cristalandia
vcoelh bd0b58f
add to_buriti_do_tocantins
vcoelh f98e240
change in _get_gazette_date
vcoelh 6b9eb02
Merge branch 'okfn-brasil:main' into ValeGazetteSpider
vcoelh 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,75 @@ | ||
from datetime import date | ||
from re import findall | ||
|
||
import scrapy | ||
import scrapy.resolver | ||
|
||
from gazette.items import Gazette | ||
from gazette.spiders.base import BaseGazetteSpider | ||
|
||
|
||
class ValeGazetteSpider(BaseGazetteSpider): | ||
""" | ||
Base spider for cities using the Framework Vale as design system. | ||
""" | ||
|
||
def start_requests(self): | ||
yield scrapy.Request(url=self._get_url(page=1), callback=self._parse_pagination) | ||
|
||
def _parse_pagination(self, response): | ||
last_page = response.css('[title="Última página"] ::attr(href)').get() | ||
if last_page: | ||
number_last_page = int(last_page.split("/")[-1]) | ||
else: | ||
number_last_page = 0 | ||
for i in range(number_last_page + 1): | ||
yield scrapy.Request(self._get_url(page=i)) | ||
|
||
def _get_url(self, page): | ||
start_date = self.start_date.strftime("%Y-%m-%d") | ||
end_date = self.end_date.strftime("%Y-%m-%d") | ||
url = ( | ||
f"https://{self.allowed_domains[0]}/diariooficial/" | ||
f"pesquisa/all/all/{start_date}/{end_date}/{page}" | ||
) | ||
return url | ||
|
||
def _get_gazette_date(self, gazette): | ||
MONTHS = { | ||
"janeiro": "01", | ||
"fevereiro": "02", | ||
"março": "03", | ||
"abril": "04", | ||
"maio": "05", | ||
"junho": "06", | ||
"julho": "07", | ||
"agosto": "08", | ||
"setembro": "09", | ||
"outubro": "10", | ||
"novembro": "11", | ||
"dezembro": "12", | ||
} | ||
|
||
website_date_text = gazette.xpath( | ||
'.//*[contains(text(), "Publicado")]/text()' | ||
).get() | ||
[day, month, year] = findall(r", (.*) de (.*) de (.*)", website_date_text)[0] | ||
datetime_date = date(int(year), int(MONTHS[month]), int(day)) | ||
return datetime_date | ||
|
||
def parse(self, response): | ||
gazettes = response.css(".ant-list-item") | ||
|
||
for gazette in gazettes: | ||
gazette_date = self._get_gazette_date(gazette) | ||
file_url = gazette.css("a ::attr(href)").get() | ||
edition_text = "".join(gazette.css(".edition-number ::text").getall()) | ||
edition_number = findall(r"(\d+)", edition_text)[0] | ||
is_extra_edition = "Extra" in edition_text | ||
yield Gazette( | ||
date=gazette_date, | ||
file_urls=[file_url], | ||
edition_number=edition_number, | ||
is_extra_edition=is_extra_edition, | ||
power="executive", | ||
) |
10 changes: 10 additions & 0 deletions
10
data_collection/gazette/spiders/to/to_buriti_do_tocantins.py
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,10 @@ | ||
from datetime import date | ||
|
||
from gazette.spiders.base.vale import ValeGazetteSpider | ||
|
||
|
||
class ToBuritiDoTocantinsSpider(ValeGazetteSpider): | ||
TERRITORY_ID = "1703800" | ||
name = "to_buriti_do_tocantins" | ||
allowed_domains = ["diario.buritidotocantins.to.gov.br"] | ||
start_date = date(2017, 3, 20) |
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,10 @@ | ||
from datetime import date | ||
|
||
from gazette.spiders.base.vale import ValeGazetteSpider | ||
|
||
|
||
class ToCristalandiaSpider(ValeGazetteSpider): | ||
TERRITORY_ID = "1706100" | ||
name = "to_cristalandia" | ||
allowed_domains = ["diario.cristalandia.to.gov.br"] | ||
start_date = date(2017, 3, 13) |
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,10 @@ | ||
from datetime import date | ||
|
||
from gazette.spiders.base.vale import ValeGazetteSpider | ||
|
||
|
||
class ToPiumSpider(ValeGazetteSpider): | ||
TERRITORY_ID = "1717503" | ||
name = "to_pium" | ||
allowed_domains = ["diario.pium.to.gov.br"] | ||
start_date = date(2021, 4, 14) |
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.
Em vez de colocar o espaço em branco , a regex ficaria mais consistente se usasse o token
\s
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.
Não seria mais interessante usar o dateparser para tratar essa data?
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.
Obrigado pela sugestão! Já subi a alteração!