-
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 branch 'master' into 446-paraguay-until-date
- Loading branch information
Showing
2 changed files
with
11 additions
and
8 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 |
---|---|---|
@@ -1,19 +1,22 @@ | ||
from datetime import date | ||
|
||
from kingfisher_scrapy.base_spider import SimpleSpider | ||
from kingfisher_scrapy.util import components, date_range_by_month | ||
|
||
|
||
class UruguayBase(SimpleSpider): | ||
download_delay = 0.9 | ||
default_from_date = '2017-11' | ||
|
||
@classmethod | ||
def from_crawler(cls, crawler, from_date=None, *args, **kwargs): | ||
if not from_date: | ||
from_date = cls.default_from_date | ||
|
||
return super().from_crawler(crawler, date_format='year-month', from_date=from_date, *args, **kwargs) | ||
|
||
def start_requests(self): | ||
url = 'http://comprasestatales.gub.uy/ocds/rss/{0.year:d}/{0.month:02d}' | ||
|
||
start = date(2017, 11, 1) | ||
stop = date.today().replace(day=1) | ||
if self.sample: | ||
start = stop | ||
self.from_date = self.until_date | ||
|
||
for d in date_range_by_month(start, stop): | ||
for d in date_range_by_month(self.from_date, self.until_date): | ||
yield self.build_request(url.format(d), formatter=components(-2), callback=self.parse_list) |