[英]Run a script every hour on a specific day
我想使用高级 Python 调度程序( https://apscheduler.readthedocs.io/en/stable/ )以便每小时从谷歌(列表市场的 40 家杂货店,从 6:00 到 18:00)抓取热门时间) 在特定的一天。
如果我每小时手动启动它,我的代码就可以工作,但我不知道如何编写正确的代码来启动 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()
所以我更正了代码中的日期并尝试再次运行它。 但同样,它没有用。 结果数据框为空。 如果我手动启动该代码(数据框不为空),则该代码有效。 因此,如果有人知道调度程序的代码有什么问题,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.