Forums

New to Python Anywhere. Need to run a Python script every minute

Hello,

I'm new to Python Anywhere... Basically, I need to run a simple script to get data from a csv file and send it to a web API. How to get started? Any help? Thanks in advance!

Could you provide us with more details on the flow / design? For example is the script to be run periodically? What triggers reading the data? Is the csv file always the same or would there be multiple files uploaded by users, etc. With such information we could guide you which features of PythonAnywhere could suit your case best.

Hi, Sure, thanks! It is a single CSV file, and I need to push the data into a Power BI streaming dataset. So, either the script runs every minute (or few seconds) or it auto-runs after it ends, to search for new data. Let me know if more info is necessary.

If you need it to run every minute, you'd need a paid account -- then you could write a script that did something like:

import time

while True:
    ## code to upload the file
    time.sleep(60)

...and then set it up as an always-on task.

However, if you have some kind of code that is updating the CSV file, then perhaps you could somehow add the code to do the upload to the end of that? What is it that is updating the CSV file?

Hi, Thanks. The CSV file is being extracted from an external application, so I think some sort of infinite loop or always-on task will do the job. Now I wonder what kind of paid account I need to do this, would the lower one help? Thanks for your help!

I think it would be best to start off with a Hacker account, yes. If your script uses lots of CPU time when processing the CSV, you might need to upgrade it, but you can do that at any time -- you'll receive an email if you run out of CPU.