如何解决在特定日期每小时运行一个脚本
我想使用高级 Python 调度程序 (https://apscheduler.readthedocs.io/en/stable/) 以便在特定日期每小时(列表市场中的 40 家杂货店,从 6:00 到 18:00)从 Google 抓取热门时间。
如果我每小时手动启动它,我的代码就可以工作,但我不知道如何编写正确的代码来启动 AP 调度程序。它运行了很长时间,但结果数据框是空的。
我正在查看手册和其他问题,但我不知道如何编写代码。
from apscheduler.schedulers.blocking import BlockingScheduler
def job():
for market in markets:
data = livepopulartimes.get_populartimes_by_address(market)
current_popularity_ = pd.DataFrame([[date.today().strftime("%Y-%m-%d"),date.today().strftime("%A"),datetime.Now().strftime("%H:%M:%s"),pd.DataFrame.from_dict(data,orient='index').loc['current_popularity'].values[0]
]],columns=['date','day','time','value'])
current_popularity_['market'] = market
current_popularity = current_popularity.append(current_popularity_)
sched = BlockingScheduler()
sched.add_job(
job,trigger='cron',hour='06-18',start_date = '2021-02-04',end_date = '2021-02-04'
)
sched.start()
解决方法
所以我更正了代码中的日期并尝试再次运行它。 但是,它再次不起作用。结果数据框为空。 如果我手动启动该代码(数据框不为空),则该代码有效。 因此,如果有人知道调度程序的代码有什么问题,请告诉我。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。