Udit Vashisht
Author: Udit Vashisht


How to host and schedule your python script on PythonAnywhere?

PythonAnywhere पर अपनी Python स्क्रिप्ट को होस्ट और शेड्यूल कैसे करें?

  • Jan. 19, 2019, 1:23 p.m.
  • 2 minutes read
  • 220 Views
How to host and schedule your python script on PythonAnywhere?

In our last post here, we learned how to create a python script which will automatically delete your messages from gmail account based on a query.

The complete ready-to-use code can be found here.

Follow the steps in the above tutorial to download the ‘credentials.json’ file and then run the init() method to create the ‘token.json’ file, as we will be needing both of them for hosting our script on PythonAnywhere.

If you don’t already have an account on PythonAnywhere create one and choose the ‘Beginner Account’ at signup as it is free.

host_python_script_on_pythonanywhere_for_free_in_hindi.png

Once you have signed up and verified your account. Go to ‘Files’, select ‘Upload a file’ and upload ‘credentials.json’, ‘token.json’ and ‘auto_delete.py’. Make sure to add your desired query in the last part of the script:-

if __name__ == '__main__':
    logger.info("Deleting messages from abc@gmail.com.")
    delete_messages('from:abc@gmail.com\
            subject:"Go Shopping"\
            older_than:1d'
                    )

host_python_script_on_pythonanywhere_for_free_in_hindi_2.png

Now, select tasks and give the path of ‘auto_delete.py’ file, if your are following this tutorial, the path will be

/home/**yourusername**/auto_delete.py

Select a time when you want the script to run. For the very beginning, you can set it 2-3 minutes later than current time to check if there is any error log or something.

host_python_script_on_pythonanywhere_for_free_in_hindi_3.png

If there are no errors, then you are good to go. Also, in addition to the log created by PythonAnywhere, one more file name ‘auto_delete.log’ will be created in your home folder which will have all your logged message.

In the beginner account you can only have one scheduled script, if you want this same script to run more than one time in a day you have to opt for paid plans on PythonAnywhere.

In case of any issues, feel free to ask in the comment section.



Related Posts

Matplotlib Stack Plots/Bars | Matplotlib Tutorial in Python | Chapter 4
By Udit Vashisht | 1 month, 3 weeks ago

Matplotlib Tutorial in Python

*Matplotlib Stack Plots/Bars | Chapter 4

In this chapter we will learn to create Matplotlib/Python Stack Plots/Bars.Stack Plots are also called area graphs/plots in general.

Matplotlib Tutorials in Python - Creating a Simple Stack Plot in Matplotlib

A good example of using a stack ...

Read More
Chapter 6 - Data Types & Variables
By Udit Vashisht | 7 months, 2 weeks ago

Variables

If we go by the dictionary meaning ‘Variable’ is something which is ‘able to be changed or adapted’. Which is true to much extent in terms of Python also. Variable is basically a reference to the memory location where an object is stored by a computer program. The names ...

Read More
Chapter 7- Numbers, Conversions and Operators
By Udit Vashisht | 7 months, 1 week ago

In the previous chapter, we learned about various data types. From this chapter onward, we will learn in detail about each data type.

Numbers

This data type stores the numeric values and is immutable. For the beginners, it is sufficient to understand that immutable objects are those which can not ...

Read More
Search