Skip to content

Commit

Permalink
Remove date conversions from base_spider
Browse files Browse the repository at this point in the history
  • Loading branch information
romifz committed Sep 17, 2020
1 parent be0eba6 commit 9bd5665
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions kingfisher_scrapy/base_spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,20 @@ def from_crawler(cls, crawler, *args, **kwargs):
if not spider.from_date:
# Default to `default_from_date` class attribute.
spider.from_date = spider.default_from_date
try:
if isinstance(spider.from_date, str):
# convert to date format, if needed
spider.from_date = datetime.strptime(spider.from_date, spider.date_format)
else:
try:
if isinstance(spider.from_date, str):
spider.from_date = datetime.strptime(spider.from_date, spider.date_format)
except ValueError as e:
raise SpiderArgumentError('spider argument from_date: invalid date value: {}'.format(e))
except ValueError as e:
raise SpiderArgumentError('spider argument from_date: invalid date value: {}'.format(e))

if not spider.until_date:
spider.until_date = cls.get_default_until_date(spider)
try:
if isinstance(spider.until_date, str):
# convert to date format, if needed
spider.until_date = datetime.strptime(spider.until_date, spider.date_format)
else:
try:
spider.until_date = datetime.strptime(spider.until_date, spider.date_format)
except ValueError as e:
raise SpiderArgumentError('spider argument until_date: invalid date value: {}'.format(e))
except ValueError as e:
raise SpiderArgumentError('spider argument until_date: invalid date value: {}'.format(e))

return spider

Expand Down

0 comments on commit 9bd5665

Please sign in to comment.