I'm using schedule to automate a few things and would like one task to be executed between two certain hours of day, twice a day. Basically, what I'm looking for, would be a command like:
schedule.between("08:00", "18:00").do(job)
Is it possible to create a helper function or similar to make this valid?
Related
This question already has answers here:
How to use python to schedule tasks in a Django application
(2 answers)
Closed 9 months ago.
I want to make a website where every month a fixed amount will increase in student's database. I want that i'll write a function and the function will run every first day of a month
I Want to Add a certain amount of fees to be added in every individual student account every month.
To do that, I need to run a function in the 1st day of month. How do I run a function continuously after every month?
Creating a function that's triggered on an hourly basis would be a good idea. Scheduled jobs/tasks, like adding monthly fees, are good candidates for this.
You could also look into cron jobs, which would be useful if you're on a Linux server, or task scheduler for Windows.
Here's a decent tutorial on how to make timer triggered cloud functions with AWS:
https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents-tutorial.html
I Found a solution by searching here and there...
I need a package to be installed and then that'll do the job!!
Here's the link for that answer.
I am working on a python script that puts information of a large number of ids to a mongo database. My scripts iterate through these ids and add them to the database based on today's date. However, the number of ids are too many and the script take many hours to run and iterate over all the ids.
Let's say I start running the script today and runs till tomorrow but somehow fails before finishing. I wanted to ask if there's a way for me to make sure that the script runs from where it left off, instead of starting again from the beginning. I want to do this because firstly, I don't want duplicate values in the database, because now these ids will be added to the database based on tomorrow's date, thus differentiating them from today. And secondly, it is a waste of time to start the loop of the ids from beginning.
Basically, I'm trying to find an answer for something like this How can I create a script that picks up where it left off in case of failure?, but for Python.
The title is self explanatory. I would like to create a new record for a user at the start of each month. What is the best way to achieve this in Django?
My initial thoughts were to run a function that will check the date time every x amount of intervals and then if year and month of last record != then create a new record. Is this even possible? It seems that this constant checking of time would be inefficient but I am struggling to think of another solution.
Am I headed in the right direction?
In web application, the best way to do this is to rely on system task scheduler, like cron in linux, to execute your code at a given time. You can schedule your task every day at midnight, and check for each user if this month's record is there, and create it if it is not there.
Here is an article on how to make cron jobs with django https://gutsytechster.wordpress.com/2019/06/24/how-to-setup-a-cron-job-in-django/
I know there are a lot of schedule and event libraries out there but I haven’t found one where I can make complex schedule. E.g
run python command every 500ms between 7.55 and 8.05 on Monday-Friday
Anyone who can easily crack that task in Python? I have considered using schedule but as far as I can tell then I can’t add something like every 500 ms. Although I do believe in a cron-like approach (except cron only allows down to every minute).
I’m thinking of calculating next “cron” time and then use sched to execute the command with the calculated delay. No idea how to calculate something like that though. I could someone already cracked this challenge though.
Turns out the apscheduler supports exactly what I'm looking for.
I'm creating RSS app in PyQt and I'm trying to find a good way to program updates. I found this Executing periodic actions in Python but maybe there is Qt specific way to do this things.
I know update period for each feed so I want to run update at specific time(hh:mm).
Making 10 minute loop that will check current time and run a update if its grater than next predicted feed update seems missing the point of knowing specific time to run it.
You should use QTimer in Qt applications. Usually you don't need to care about specific update time, as the goal is regular periodic check. So the most straightforward approarch is to create a timer for each feed and set the update interval of each timer (e.g. 10 minutes).
If you for some reason really want to make an update at specific time, you can use something like QDateTime::currentDateTime().msecsTo(targetTime) to calculate timer interval, use QTimer::setSingleShot to make the timer non-periodic and set another timer when the first one is expired.
It may be reasonable to do timer->setTimerType(Qt::VeryCoarseTimer) because you don't need much accuracy and Qt can optimize performance and power consuming in some cases.
Note that you generally cannot use Python's means to set up timers because Qt has its own event loop and won't allow other libraries to run something in the middle of it.