0

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.

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. 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() 
9
  • 4
    can you explain why you want to use this instead of a more standard solution? (on Windows: scheduled tasks. On Linux/Mac: cron. On AWS: lambda, etc) Commented Jan 30, 2021 at 6:40
  • 1
    You are saying the script was running correctly for some time, but stopped without you changing anything? Commented Jan 30, 2021 at 6:49
  • 1
    The end_date arguments has a value already in the past. Does it mean the scheduler runs forever, or it never runs? Commented Jan 30, 2021 at 7:51
  • 2
    The start_date and end_date values don't make any sense since they indicate the schedule should end 10 years earlier than it should start. Also the fact that they're both in the past mean the schedule will never run. Commented Jan 30, 2021 at 21:46
  • 1
    OMG, I haven't checked the dates! Indeed, I wanted to run the script on 2021-01-07. Shame on me... Commented Feb 4, 2021 at 10:41

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Same problem here - its not the dates

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.