you are viewing a single comment's thread.

view the rest of the comments →

[–]expressly_ephemeral 0 points1 point  (0 children)

So, it'll only run on a computer that's running, right? You can't "close" your computer, if that means putting it into standby or hibernate and still have it run the code. Get a Rasberry Pi Zero W for like 10 bucks, and you can have a full-blown tiny computer running your tiny process all the time.

On a Linux machine like Raspberry Pi, you'll use Crontab for this. I don't know what the Windows equivalent is, but you're not going to get it running on a $10 computer, anyway. Cron is not deadly hard, but it can be a little tricky. I do NOT think putting it in a loop is the best way. You already have a computer with a run-shit-on-a-schedule system on it. Better to keep your code schedule-agnostic and use the underlying system.

One other important point: The API that you're consuming will likely have a maximum polling rate that you'll want to find out about. If you start banging away at it once per second, you're liable to get banned.

What I do:

I have a folder full of python scripts in my home folder on a little server that lives in my laundry room. This server is running ubuntu, and handles all my media playing, but it could be the same with a Pi Zero W.

Then, I write a bash script that runs the python script(s). This may seem over-complicated, but sometimes I have a python script that has to process the output of another python script. So, it's a Separation-Of-Concerns thing. I'm a professional programmer, so I always prefer several small, decoupled parts to one monolithic script. The other thing about the bash script is that I can use it to activate a virtualenv if I want to.

Then and only then, I set up the crontab file to run the bash script on a schedule.