Skip to content

Commit af95ebe

Browse files
committed
Use delorean to handle timezones.
1 parent cf912cd commit af95ebe

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

manolo_scraper/manolo_scraper/spiders/spiders.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import re
55
from exceptions import NotImplementedError
66

7+
78
import scrapy
89
from scrapy import exceptions
10+
from delorean import Delorean, parse
911

1012
from ..items import ManoloItem
1113
from ..item_loaders import ManoloItemLoader
@@ -20,7 +22,9 @@ def __init__(self, date_start=None, date_end=None, *args, **kwargs):
2022
self.date_start = date_start
2123
self.date_end = date_end
2224

23-
today = datetime.date.today()
25+
d = Delorean()
26+
d.shift("America/Lima")
27+
today = d.date
2428

2529
if self.date_start is None:
2630
self.date_start = today.strftime('%Y-%m-%d')
@@ -39,8 +43,8 @@ def days_between_dates(date_start, date_end):
3943
return delta.days
4044

4145
def start_requests(self):
42-
d1 = datetime.datetime.strptime(self.date_start, '%Y-%m-%d').date()
43-
d2 = datetime.datetime.strptime(self.date_end, '%Y-%m-%d').date()
46+
d1 = parse(self.date_start, dayfirst=False, yearfirst=True).date
47+
d2 = parse(self.date_end, dayfirst=False, yearfirst=True).date
4448
# range to fetch
4549
delta = d2 - d1
4650

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
alembic==0.8.8
22
attrs==16.2.0
3+
Babel==2.3.4
34
cffi==1.8.3
45
click==6.6
56
colorama==0.3.7
67
cryptography==1.5.2
78
cssselect==0.9.2
89
dataset==0.7.0
10+
Delorean==0.6.0
911
enum34==1.1.6
1012
hubstorage==0.23.2
13+
humanize==0.5.1
1114
idna==2.1
1215
ipaddress==1.0.17
1316
lxml==3.6.4
@@ -21,8 +24,10 @@ pyasn1-modules==0.0.8
2124
pycparser==2.14
2225
PyDispatcher==2.0.5
2326
pyOpenSSL==16.1.0
27+
python-dateutil==2.5.3
2428
python-editor==1.0.1
2529
python-termstyle==0.1.10
30+
pytz==2016.6.1
2631
PyYAML==3.12
2732
queuelib==1.4.2
2833
rednose==1.2.1
@@ -36,6 +41,7 @@ shub==2.4.2
3641
six==1.10.0
3742
SQLAlchemy==1.0.15
3843
Twisted==16.4.1
44+
tzlocal==1.2.2
3945
Unidecode==0.4.19
4046
Unipath==1.1
4147
w3lib==1.15.0

0 commit comments

Comments
 (0)