-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1089 from open-contracting/1088-guatemala
feat: add guatemala_bulk
- Loading branch information
Showing
4 changed files
with
78 additions
and
3 deletions.
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
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,65 @@ | ||
from datetime import datetime | ||
|
||
import scrapy | ||
|
||
from kingfisher_scrapy.base_spiders import SimpleSpider | ||
from kingfisher_scrapy.util import components, handle_http_error | ||
|
||
|
||
class GuatemalaBulk(SimpleSpider): | ||
""" | ||
Domain | ||
Ministerio de Finanzas Públicas - Dirección General de Adquisiciones del Estado | ||
Spider arguments | ||
from_date | ||
Download only data from this month onward (YYYY-MM format). | ||
If ``until_date`` is provided, defaults to '2020-01'. | ||
until_date | ||
Download only data until this month (YYYY-MM format). | ||
If ``from_date`` is provided, defaults to the current month. | ||
API documentation | ||
https://ocds.guatecompras.gt/api-ocds | ||
Bulk download documentation | ||
https://ocds.guatecompras.gt/descarga-datos | ||
""" | ||
name = 'guatemala_bulk' | ||
|
||
# BaseSpider | ||
date_format = 'year-month' | ||
default_from_date = '2020-01' | ||
|
||
# SimpleSpider | ||
data_type = 'record_package' | ||
|
||
def start_requests(self): | ||
url = 'https://ocds.guatecompras.gt/files' | ||
yield scrapy.Request(url, meta={'file_name': 'list.json'}, callback=self.parse_list) | ||
|
||
@handle_http_error | ||
def parse_list(self, response): | ||
# An example of expected response is: | ||
# { | ||
# "id": "gc-{year}-{month}" | ||
# "results": [ | ||
# { | ||
# "files": { | ||
# "csv": "...", | ||
# "sha": "...", | ||
# "json": "...", | ||
# "xlsx": "..." | ||
# }, | ||
# "year": "values between 2020 to the current year", | ||
# "month": "values between 1 and 12", | ||
# "monthName": "values between enero to diciembre", | ||
# "source": "Guatecompras", | ||
# "timestamp": "last updated date in timestamp with time zone format" | ||
# }, ... | ||
# ] | ||
# } | ||
for item in response.json()["result"]: | ||
if self.from_date and self.until_date: | ||
date = datetime(int(item['year']), int(item['month']), 1) | ||
if not (self.from_date <= date <= self.until_date): | ||
continue | ||
|
||
yield self.build_request(item['files']['json'], formatter=components(-2)) |
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
2 changes: 1 addition & 1 deletion
2
kingfisher_scrapy/spiders/mexico_puebla_state_seseap_plataforma_digital_nacional.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