1 Star 1 Fork 0

stoneqp/eastmoney_stock

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
run.py 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
jeremy 提交于 2018-04-14 11:20 . 使用celery配置程序自动运行时间
import time
from scrapy import cmdline
from eastmoney.pipelines import EastmonyMysqlPipeline
# 立即执行爬虫
def now_play():
# 运行前先清理上一次执行的数据
EastmonyMysqlPipeline().truncate_table()
cmdline.execute("scrapy crawl gupiao".split())
# 指定时间点执行爬虫
def set_time(the_time):
# 实时监控
while True:
# 当前时间戳
now_tamp = int(time.time())
# 指定需要监控的时间点
target_time = str(the_time)
# 转换成时间数组
time_array = time.strptime(target_time,"%Y-%m-%d %H:%M:%S")
# 转换成时间戳
times_tamp = int(time.mktime(time_array))
# 判断当前时间是否已经到了指定时间点
if now_tamp == times_tamp:
print('当前时间是:%s'%str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))))
# 运行前先清理上一次执行的数据
EastmonyMysqlPipeline().truncate_table()
# 执行爬虫程序
cmdline.execute("scrapy crawl gupiao".split())
break
if __name__ == '__main__':
# 输入要开始爬取的时间点,精确到秒
# set_time('2018-04-12 16:14:00')
now_play()
'''
此处的执行文件只是用在未安装celery模块时使用,更好的启动方式可以使用tasks.py文件
'''
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/stoneqp/eastmoney_stock.git
git@gitee.com:stoneqp/eastmoney_stock.git
stoneqp
eastmoney_stock
eastmoney_stock
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385