Skip to main content

iCal is a relatively compact albeit unintuitive and inconvenient text format for calendaring and scheduling information. Recurring events can be defined through a large set of rules, which makes the format compact but inconvenient for automatic processing. The intention of this package is to provide functions to ease the automatic processing of iCalendar files by converting the iCalendar information into a timetable.

Installation

Timetable requires Python 2 or 3. You can install Timetable easily via pip:

$ pip install timetable

Documentation & Code

You can find a short guide, some examples, and the API reference in the online documentation. The source code is available on Bitbucket.

If you find any bugs, please post them in the issue tracker.

Getting started

A timetable is a sorted sequence of tuples containing start and end datetime of an entry, for example (start, end, entry). start and end are datetime offset-naive objects (e.g. containing no timezone information) in UTC time. The entry is a dictionary, containing arbitrary values.

The following example is a valid timetable list:

[
    (datetime(2015, 1, 1, 12), datetime(2015, 1, 1, 13), {}),
    (datetime(2015, 1, 2, 12), datetime(2015, 1, 2, 13), {}),
    (datetime(2015, 1, 3, 12), datetime(2015, 1, 3, 13), {}),
]

Timetables can be generated from iCal files. The following example shows how a timetable is generated from all VEVENT entries in a iCal calendar. The example prints the start datetime of each entry as well as the calendar events summary:

>>> from timetable import parse_ical, generate_timetable
>>>
>>> icaldata = b"""
... BEGIN:VCALENDAR
... BEGIN:VEVENT
... UID:0
... DTSTART:20150101T120000Z
... DTEND:20150101T130000Z
... RRULE:FREQ=DAILY;COUNT=3;BYDAY=TH,FR
... SUMMARY:event a
... END:VEVENT
... BEGIN:VEVENT
... UID:1
... DTSTART:20150101T123000Z
... DTEND:20150101T133000Z
... RRULE:FREQ=DAILY;COUNT=3
... SUMMARY:event b
... END:VEVENT
... END:VCALENDAR
... """
>>> calendar = parse_ical(icaldata)[0]
>>> for start, end, entry in generate_timetable(calendar, b'vevent'):
...     summary = str(entry['item'][b'summary'][0].value.decode('utf-8'))
...     print('%s %s' % (start.isoformat(), summary))
2015-01-01T12:00:00 event a
2015-01-01T12:30:00 event b
2015-01-02T12:00:00 event a
2015-01-02T12:30:00 event b
2015-01-03T12:30:00 event b
2015-01-08T12:00:00 event a

spam or eggs?

Timetable data can be used to calculate metrics for time management, like for example, compute the time spent in meetings or working on projects.

However, of more pressing concern is the question if you spent more time eating eggs or spam for lunch in two months, assuming you eat spam for 45 minutes but only every other week on monday and tuesday whereas you eat eggs for 15 minutes every week but only from wednesday to friday:

>>> from datetime import datetime, timedelta
>>> from timetable import parse_ical, generate_timetable, clip_timetable
>>>
>>> icaldata = b"""
... BEGIN:VCALENDAR
... BEGIN:VEVENT
... UID:0
... DTSTART:20150101T120000Z
... DTEND:20150101T124500Z
... RRULE:FREQ=WEEKLY;BYDAY=MO,TU;INTERVAL=2
... SUMMARY:spam
... END:VEVENT
... BEGIN:VEVENT
... UID:1
... DTSTART:20150101T120000Z
... DTEND:20150101T121500Z
... RRULE:FREQ=WEEKLY;BYDAY=WE,TH,FR
... SUMMARY:eggs
... END:VEVENT
... END:VCALENDAR
... """
>>> calendar = parse_ical(icaldata)[0]
>>>
>>> start = datetime(2015, 1, 1)
>>> end = datetime(2015, 3, 1)
>>> timetable = clip_timetable(generate_timetable(calendar), start, end)
>>>
>>> time = {b'spam': 0, b'eggs': 0}
>>> for start, end, entry in timetable:
...     food_name = entry['item'][b'summary'][0].value
...     time[food_name] += (end - start).total_seconds() / 3600
>>>
>>> print('spam: %.2f, eggs: %.2f' % (time[b'spam'], time[b'eggs']))
spam: 6.75, eggs: 6.50

It looks like spam.

Metadata

Release files for timetable 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for timetable 0.2
File Size Uploaded Provenance Actions
timetable-0.2.tar.gz 12.2 kB Without provenance Details for timetable-0.2.tar.gz

Release files / timetable-0.2.tar.gz

Download URL timetable-0.2.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c12a2ecd5bc6126d3b1268167f7b2762de9645d50355b2692c531cf38fa27765
BLAKE2b-256 checksum
How to use checksums
bc3f38be89eb6c3b08acb557e5266d7501f0a0fbad80aa9b5a4114b27ea832c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for timetable 0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page