Skip to main content

A Python module and program to convert calendars using X-WR-TIMEZONE to standard ones.

Project description

Travis Build and Tests Status Python Package Version on Pypi Downloads from Pypi

Some calendar providers introduce the non-standard X-WR-TIMEZONE parameter to ICS calendar files. Strict interpretations according to RFC 5545 ignore the X-WR-TIMEZONE parameter. This causes the times of the events to differ from those which make use of X-WR-TIMEZONE.

This module aims to bridge the gap by converting calendars using X-WR-TIMEZONE to a strict RFC 5545 calendars. So, let’s put our heads together and solve this problem for everyone!

Some features of the module are:

  • Easy install with Python’s pip.

  • Command line conversion of calendars.

  • Piping of calendar files with wget of curl.

Some of the requirements are:

  • Calendars without X-WR-TIMEZONE are kept unchanged.

  • Passing calendars twice to this module does not change them.

Install

Install using pip:

python3 -m pip install x-wr-timezone

Command Line Usage

You can standardize the calendars using your command line interface. The examples assume that in.ics is a calendar which may use X-WR-TIMEZONE. whereas out.ics does not require X-WR-TIMEZONE for proper display.

cat in.is | x-wr-timezone > out.ics
x-wr-timezone in.ics out.ics
curl https://example.org/in.ics | x-wr-timezone > out.ics
wget -O- https://example.org/in.ics | x-wr-timezone > out.ics

Python

After you have installed the library, you an import it.

import x_wr_timezone

The function to_standard() converts an icalendar object.

x_wr_timezone.to_standard(an_icalendar)

Here is a full example which does about as much as this module is supposed to do:

import icalendar # installed wih x_wr_timezone
import x_wr_timezone

with open("in.ics", 'rb') as file:
    calendar = icalendar.from_ical(file.read())
new_calendar = x_wr_timezone.to_standard(calendar)
# you could use the new_calendar variable now
with open('out.ics', 'wb') as file:
    file.write(new_calendar.to_ical())

to_standard(calendar, timezone=None, in_place=False) has these parameters:

  • calendar is the icalendar calendar object.

  • timezone is an optional time zone. By default, the time zone in

    calendar['X-WR-TIMEZONE'] is used to check if the calendar needs changing. When timezone is not None however, calendar['X-WR-TIMEZONE'] will not be tested and it is assumed that the calendar should be changed as if calendar['X-WR-TIMEZONE'] had the value of timezone. This does not add or change the value of calendar['X-WR-TIMEZONE']. You would need to do that yourself.

  • in_place is set to False by default so that a changed copy

    of the calendar argument is returned. Set in_place=True to have the calendar argument be changed and returned.

Development

  1. Clone the repository or its fork and cd x-wr-timezone.

  2. Optional: Install virtualenv and Python3 and create a virtual environment.
    virtualenv -p python3 ENV
    source ENV/bin/activate
  3. Install the packages.
    pip install -r test-requirements.txt -e .
  4. Run the tests
    pytest

New Releases

To release new versions,

  1. edit the Changelog Section

  2. edit setup.py, the __version__ variable

  3. create a commit and push it

  4. Wait for Travis to finish the build.

  5. run
    python3 setup.py tag_and_deploy
  6. notify the issues about their release

Testing

This project’s development is driven by tests. Tests assure a consistent interface and less knowledge lost over time. If you like to change the code, tests help that nothing breaks in the future. They are required in that sense. Example code and ics files can be transferred into tests and speed up fixing bugs.

You can view the tests in the test folder. If you have a calendar ICS file for which this library does not generate the desired output, you can add it to the test/calendars folder and write tests for what you expect. If you like, open an issue first, e.g. to discuss the changes and how to go about it.

Changelog

  • v0.0.1
    • Initial release supports DTSTART, DTEND, EXDATE, RDATE, RECURRENCE-ID attributes of events.

    • Command line interface as x-wr-timezone.

License

This software is licensed under LGPLv3, see the LICENSE file.

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

x_wr_timezone-0.0.1.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

x_wr_timezone-0.0.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file x_wr_timezone-0.0.1.tar.gz.

File metadata

  • Download URL: x_wr_timezone-0.0.1.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for x_wr_timezone-0.0.1.tar.gz
Algorithm Hash digest
SHA256 89ced9341f4a660a4f6ece2d52f52535bc72acf4ffa4b65d63149a7d43010443
MD5 cccb06ea56108eed58403a26d971ee79
BLAKE2b-256 9b01e7393980b8ce507b2cb598d9f0a4e1fdf84d16b6c7bd01a4d0f3b0014e16

See more details on using hashes here.

File details

Details for the file x_wr_timezone-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: x_wr_timezone-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for x_wr_timezone-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b262340d32b0382c340c8dfd580a16964a11871135428e3fdb9e009916567b78
MD5 86db7cee7c5afcc6924df699ec498084
BLAKE2b-256 b2a2efb600d73cc771689a543bb2e1a491a1e363ffb9c5b99a383efa8c3aec4f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page