A systemd.timer inspired event parser in pure Python.
Project description
justnow
justnow
is a systemd.timer inspired event parser in pure Python. The library consists of a lark grammar definition and some code to parse and generate datetimes.
Usage
Below is a snippet of the basic usage.
import datetime
from justnow.parser import EventParser
reference_date = datetime.datetime(2020, 1, 1)
# "sat *-*-* 14:00:00" => Generate all Saturdays at 14:00:00
parser = EventParser("sat *-*-* 14:00:00", reference_date=reference_date)
next(parser) # datetime.datetime(2020, 1, 4, 14, 0)
# "sat *-02-29" => Generate all Saturdays which occur on a leap year
parser = EventParser("sat *-02-29", reference_date=reference_date)
list(parser.get_next_n(limit=2)) # [datetime.datetime(2020, 2, 29, 0, 0), datetime.datetime(2048, 2, 29, 0, 0)]
The justnow
grammar defines a time event
and is made of up 3 sections:
Weekday section
This section allows for a comma separated list of weekday names and weekday ranges.
Weekday names
The following are valid tokens for the weekday section:
- mon
- tue
- wed
- thu
- fri
- Mon
- Tue
- Wed
- Thu
- Fri
- monday
- tuesday
- wednesday
- thursday
- friday
Weekday ranges
A weekday range consists of two day names separated by two full stops.
For example mon..wed
will evaluate into mon, tue and wed.
Date section
The date section is made up of 3 sub sections, namely:
- A year section
- A month section
- A day section
Each of the above sub sections can be either:
- One of more fixed length strings made up of integers separated by a comma. The length is 4 for years and 2 for months and days.
- A wildcard
*
Time section
The time section is made up of 3 sub sections, namely:
- A hour section
- A minute section
- A second section
Each of the above sub sections can be either:
- One of more strings made up of 2 integers separated by a comma.
- A wildcard
*
Named Events
justnow
also supports a set of built in named events including:
@minutely
@hourly
@daily
@monthly
@weekly
@yearly
@quarterly
@semiannually
@annually
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file justnow-0.1.4.tar.gz
.
File metadata
- Download URL: justnow-0.1.4.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/5.8.3-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 004b6e91ca56a16dbf43577d0820877e62ae3e99300f6f4d3ef40c428e674e02 |
|
MD5 | c5b1d96ad81d266f8aea348021e94ef8 |
|
BLAKE2b-256 | 6fb88d684edb76af3ed258214a865ee11c2bf72e555d7f92b337a2aca809d9e3 |
File details
Details for the file justnow-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: justnow-0.1.4-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/5.8.3-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 985aceba11f1f5061dba16b5b0023c3c91a46b7136e3cf888363d2e30b5b5556 |
|
MD5 | 0eaf050d031cf5d533796020d36b1813 |
|
BLAKE2b-256 | 5781ee33d1f4db1bd4070219af844e41c2e6c3590087935dce09ba4f75248104 |