Keeping the computer on 24/7 is not practical, so if you want to execute a Python script at a particular time every day, you probably need a computer that is ON all the time. To make this possible, a website PythonAnywhere gives you access to such a 24/7 computer. You can upload a Python script and schedule it to run at a certain time every day. This availability can be useful, for example, when you want to extract some values (e.g., weather data) from a website and generate a text file with the value or other reports every day.
To schedule, a Python script for execution on PythonAnywhere, follow these simple steps:
- Sign up on here the account for Beginners is free with some T&C.
- Go to your Dashboard, Files, Upload a File and upload the Python file you want to schedule for execution.
- Go to Tasks and set the time of the day you want your script to be executed and type in the name of the Python file you uploaded (e.g., myfirstpyscript.py).
Note: The time entered should be in UTC. - Click “create” and you are done.
The Python file will now be executed every day at your specified time.
Example: Below is a very simple Python script you can use to schedule for execution.
from datetime import datetime # Saves a .txt file with file name # as 2020-01-11-10-20-23.txt with open(datetime.now().strftime("%Y-%m-%d-%H-%M-%S"), "w")as myfile: # Content of the file myfile.write("Hello World !") |
The above code creates a text file and writes the string “Hello World!” in that text file. The name of the text file will be the current date and time. For example one file name example would be 2020-01-11-10-20-23.txt.
That name is generated by datetime.now() indicating the date and time the script was executed. Every time the script is executed, the script generates a new text file with a different name. You will have a new text file created every day.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- How to Deploy Django project on PythonAnywhere?
- Python | Schedule Library
- Python | Add Logging to a Python Script
- Python script to open a Google Map location on clipboard
- Run Python script from Node.js using child process spawn() method
- Autorun a Python script on windows startup
- Python | Accepting Script Input
- Python Script to Shutdown Computer
- Python Script to Restart Computer
- Python Script to Logout Computer
- Run python script from anywhere in linux
- Get directory of current Python script
- How to Run a Python Script
- Convert Python Script to .exe File
- Add a User in Linux using Python Script
- Deleting a User in Linux using Python Script
- Get Your System Information - Using Python Script
- Python script to change MAC address of Linux machine
- Run Python Script using PythonShell from Node.js
- Create a Python Script Notifying to take a break
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

