Open Victornovikov opened 3 years ago
Two things: 1) I wrote it as a script...can I embed all this code into a function called main() and just call main()? 2) Does using sleep() mean that my code is always running in the background? I thought of this but didn't want to constantly run the computer
On Wed, May 19, 2021 at 3:35 PM Victor @.***> wrote:
Is there a reason you didn't make it an "app"/library that leverages main?
you technically have two functions that call pull data and one that sends a message. You can run them in a loop with sleep() (whenever stats are changing) and that way you have an actual, deployable app.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/NicholasTagher/SportsCalendar/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOOPCKNZM5GFL2TNS7PMZTTOQHGXANCNFSM45FLCEFA .
Two things: 1) I wrote it as a script...can I embed all this code into a function called main() and just call main()? 2) Does using sleep() mean that my code is always running in the background? I thought of this but didn't want to constantly run the computer …
It may be useful to read about main and package imports vs executing scripts
if __name__ == "__main__":
https://www.freecodecamp.org/news/if-name-main-python-example/
You dont have to do it its, just a very popular pattern in python
There are may different ways to do it. You can have a cron job , you can have sleep(), you can do something complex, like checking periodically if there are any changes on the page and if there’re then pull data (advanced version of a sleep).
Running that script on your machine with sleep() won’t take many resources, but I was mainly thinking it could be fun to deploy it to, for example DigitalOcean, so that you have a real app running somewhere that sends you data. And that requires it to run continuously.
Is there a reason you didn't make it an "app"/library that leverages main?
you technically have two functions that call pull data and one that sends a message. You can run them in a loop with sleep() (whenever stats are changing) and that way you have an actual, deployable app.