-
Notifications
You must be signed in to change notification settings - Fork 12
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 Zaragoza spider #510
Merged
Merged
Add Zaragoza spider #510
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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,50 @@ | ||
import json | ||
|
||
import scrapy | ||
|
||
from kingfisher_scrapy.base_spider import SimpleSpider | ||
from kingfisher_scrapy.util import components, handle_http_error | ||
|
||
|
||
class SpainZaragoza(SimpleSpider): | ||
""" | ||
Swagger API documentation | ||
https://www.zaragoza.es/docs-api_sede/ | ||
Spider arguments | ||
sample | ||
Downloads the first release returned by the API release endpoint. | ||
from_date | ||
Download only data from this date onward (YYYY-MM-DDTHH:mm:ss format). | ||
If ``until_date`` is provided, defaults to '2000-01-01T00:00:00'. | ||
until_date | ||
Download only data until this date (YYYY-MM-DDTHH:mm:ss format). | ||
If ``from_date`` is provided, defaults to today. | ||
""" | ||
name = 'spain_zaragoza' | ||
data_type = 'release_list' | ||
date_format = 'datetime' | ||
default_from_date = '2000-01-01T00:00:00' | ||
url = 'https://www.zaragoza.es/sede/servicio/contratacion-publica/ocds/contracting-process/' | ||
|
||
def start_requests(self): | ||
# row parameter setting to 100000 to get all releases | ||
url = self.url + '?rf=html&rows=100000' | ||
|
||
# check date parameters and set "yyyy-MM-dd'T'HH:mm:ss'Z'" format | ||
if self.from_date and self.until_date: | ||
# `before` and `after` query string parameters behave opposite in API | ||
after = self.until_date.strftime("%Y-%m-%dT%H:%M:%SZ") | ||
before = self.from_date.strftime("%Y-%m-%dT%H:%M:%SZ") | ||
url = url + '&before={}&after={}'.format(before, after) | ||
|
||
yield scrapy.Request(url, meta={'file_name': 'list.json'}, callback=self.parse_list) | ||
|
||
@handle_http_error | ||
def parse_list(self, response): | ||
ids = json.loads(response.text) | ||
for contracting_process_id in ids: | ||
url = self.url + contracting_process_id['id'] | ||
yield self.build_request(url, formatter=components(-1)) | ||
|
||
if self.sample: | ||
return |
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.
no debería ser al revés? before until_date and after from_date?
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.
Si, debe ser al revés, pero creo que en el servicio esta así, after=2020-10-05 y before=2000-01-01 con datos, y after=2000-01-01 y before=2020-10-05 sin datos.
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.
Can you add a comment in the code, saying the
before
andafter
query string parameters behave opposite expectations? Otherwise, I'm sure a future reader will again ask the question.