简体   繁体   中英

Python restart file on windows or linux

I currently have a big long file that queries a webpage to build a dictionary. I'd like this file to restart at 4am every day as the webpage will have updated with fresh info. What do I need to put inside my while True: loop?

Current status:

##Various Imports
##Selenium code to get details
##Dictionary Compile

while True:
    now = datetime.datetime.now()
    current_time = now.strftime("%H:%M:%S")
    if current_time == ("04:00:00"):
        ##The Code to Restart the process goes here
    else:
        #Other Stuff happens with the dictionary

Building and testing on windows but will ultimately run on a Raspberry Pi

I would suggest you make the script simply get the information from the web page then do whatever it needs to do with your dictionary and end. Only one time. Then you can schedule this script to run at 4:00 AM every day with Windows Task Scheduler or with a Cron Job on linux. Here is a link on how to set up a cron job to run a python script.

If you want the functionality of a cron job in Python you could use the schedule library. It looks like it has support to keep the script running and then restart at 4AM. More can be read on this StackOverflow Question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM