Is there a Python module to get next runtime from a crontab-style time definition?

2024/9/23 20:13:06

I'm writing a dashboard application and I need a way to figure out how long an item is "valid", i.e. when should it have been superseded by a new value (it's possible to have an error such that the next value never arrives).

Since I know the schedules for the processes producing data, I can define valid as "until the next time the process should have ran".

I thought the crontab format for specifying schedules was very compact (i.e. easy to store in a database), and also easy to understand.

Finally the question: is there a Python module, that when given the current time and a crontab spec (e.g. "25 5 * * *"), returns a datetime giving the next runtime?

Answer

I ran into some issues using the code (from http://www.koders.com/python/fidA55A9DB55093A78DD26B55C606B267B2C5063A79.aspx?s=config) , and have fixed some of them. It used to break going from one month to the next. next_run now works fine, but prev_run gets stuck going from one month the previous (instead of failing it gets caught in a loop)

Here is a git repository that I've set up to continue working on it:

https://github.com/RFDaemoniac/crontab_parser

https://en.xdnf.cn/q/71697.html

Related Q&A

Django Generic Relations error: cannot resolve keyword content_object into field

Im using Djangos Generic Relations to define Vote model for Question and Answer models. Here is my vote model:models.pyclass Vote(models.Model):user_voted = models.ForeignKey(MyUser)is_upvote = models.…

How to benchmark unit tests in Python without adding any code

I have a Python project with a bunch of tests that have already been implemented, and Id like to begin benchmarking them so I can compare performance of the code, servers, etc over time. Locating the …

Digit recognition with Tesseract OCR and python

I use Tesseract and python to read digits (from a energy meter). Everything works well except for the number "1". Tesseract can not read the "1" Digit.This is the picture I send t…

Pycharm not recognizing packages even when __init__.py exits

This is my directory structure--> ProjectDirectory-->__init__.py--> BaseDirectory-->__init__.py--> AnotherBaseDirectory-->__init__.py-->program.pyinside program.pyWhen i give impor…

Scrapy is following and scraping non-allowed links

I have a CrawlSpider set up to following certain links and scrape a news magazine where the links to each issue follow the following URL scheme:http://example.com/YYYY/DDDD/index.htm where YYYY is the …

Overriding virtual methods in PyGObject

Im trying to implement the Heigh-for-width Geometry Management in GTK with Python for my custom Widget. My widget is a subclass from Gtk.DrawingArea and draws some parts of an Image.As I understood the…

How to find if two numbers are consecutive numbers in gray code sequence

I am trying to come up with a solution to the problem that given two numbers, find if they are the consecutive numbers in the gray code sequence i.e., if they are gray code neighbors assuming that the …

How do I get data from selected points in an offline plotly python jupyter notebook?

Example code:from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplotimport plotly.graph_objs as goimport numpy as npN = 30 random_x = np.random.randn(N) random_y = np.random.randn…

Set background colour for a custom QWidget

I am attempting to create a custom QWidget (from PyQt5) whose background colour can change. However, all the standard methods of setting the background colour do not seem to work for a custom QWidget c…

Plotly: How to set up a color palette for a figure created with multiple traces?

I using code below to generate chart with multiple traces. However the only way that i know to apply different colours for each trace is using a randon function that ger a numerico RGB for color. But r…