[英]Run a script every hour on a specific day
I want to use the Advanced Python Scheduler ( https://apscheduler.readthedocs.io/en/stable/ ) in order to scrape popular times from Google every hour (40 grocery stores in list markets, from 6:00 to 18:00) on a specific day.我想使用高级 Python 调度程序( https://apscheduler.readthedocs.io/en/stable/ )以便每小时从谷歌(列表市场的 40 家杂货店,从 6:00 到 18:00)抓取热门时间) 在特定的一天。
My code works if I start it manually every hour, but I don't know how to write correct code in order to start the AP Scheduler.如果我每小时手动启动它,我的代码就可以工作,但我不知道如何编写正确的代码来启动 AP 调度程序。 It was running for quite some time, but the resulting data frame was empty.它运行了很长一段时间,但生成的数据框是空的。
I was looking into the manual and other questions, but I couldn't figure out how to write the code.我正在查看手册和其他问题,但我不知道如何编写代码。
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()
So I corrected the dates in my code and tried to run it again.所以我更正了代码中的日期并尝试再次运行它。 But again, it didn't work.但同样,它没有用。 The resulting data frame was empty.结果数据框为空。 The code works if I start it manually (data frame is not empty).如果我手动启动该代码(数据框不为空),则该代码有效。 So if anyone has an idea what is wrong with the code for the scheduler, please let me know.因此,如果有人知道调度程序的代码有什么问题,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.