Hello! I have a private repl with 3-4 python scripts that use an API to pull, manipulate, and print data to a spreadsheet I have. I’ve been manually running this once a day, but would like to automate the part where I press “Run” as well.
Since I have the Hacker Plan, it’s always on. How can I set things up so that the run button is automatically pressed every day at 11am (or some other time)? Surely there’s a way to do this as long as it’s always on.
Hey @sabineleffler, welcome to the community!
Why would you need to manually hit the run button if the Repl is always on?
Hey @sabineleffler welcome to the forums!
If it is
Always On you would need a timer for that time to run then. You can’t set it up with just Replit you would need some code.
When it’s always on, does it stay running? What’s an example of a timer that I could use, and where would I put this code? For example, would I put a timer in the main.py file? Or set it up in some other way – like in the console?
@sabineleffler you would put it in the
main.py file. I don’t know how to do the actual code for it though.
As far as I know, I don’t think there is a way to do this. You can set some code up so that it shuts down when it’s not 11am, but other than that, there is, unfortunately, no way to do this.
When a Repl is set to Always On, Replit turns the Repl back on every time it gets shut off automatically. So, it turns off and them immediately back on again on its own. Deployments theoretically run 24/7, without these stops. What I would recommend is making your program get the current time, and if the time matches a specified time of yours, it will execute your function. Like this:
from time import sleep
# some code
# something to get the time
acceptable_times = ["11", "1", "3"] # I have no idea what times
# you actually want
if current_time in acceptable_times:
sleep(60) # waits 1 minute before running this again
If you used only
time.sleep to determine when to run your code, and your Repl restarts for any reason, it would mess up your timing. This should mitigate this issue.
Thanks! I’ll try putting this code into the main.py file and see if it works for my daily updates.