updated sinastock_spider: time zone adjustment

This commit is contained in:
Marvin Zhang
2019-07-07 09:34:02 +08:00
parent 2c05c720fc
commit d4bcc3c3fc

View File

@@ -5,9 +5,13 @@ from datetime import datetime
import scrapy
from pymongo import MongoClient
import pytz
from sinastock.items import NewsItem
# 时区
tz = pytz.timezone('Asia/Shanghai')
class SinastockSpiderSpider(scrapy.Spider):
name = 'sinastock_spider'
@@ -57,5 +61,7 @@ class SinastockSpiderSpider(scrapy.Spider):
if item['text'] is None or item['ts_str'] is None:
pass
else:
item['ts'] = datetime.strptime(item['ts_str'], '%Y年%m月%d%H:%M')
ts = datetime.strptime(item['ts_str'], '%Y年%m月%d%H:%M')
ts = tz.localize(ts)
item['ts'] = ts
yield item