forked from ics-py/ics-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Tom Schraitle <[email protected]>
- Loading branch information
1 parent
214d5c1
commit bc19f7f
Showing
8 changed files
with
199 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,21 +38,21 @@ Quickstart | |
$ pip install ics | ||
.. code-block:: python | ||
from ics import Calendar, Event | ||
c = Calendar() | ||
e = Event() | ||
e.name = "My cool event" | ||
e.begin = '2014-01-01 00:00:00' | ||
c.events.add(e) | ||
c.events | ||
# [<Event 'My cool event' begin:2014-01-01 00:00:00 end:2014-01-01 00:00:01>] | ||
with open('my.ics', 'w') as my_file: | ||
my_file.writelines(c) | ||
# and it's done ! | ||
from datetime import datetime | ||
from ics import Calendar, Event | ||
c = Calendar() | ||
e = Event() | ||
e.summary = "My cool event" | ||
e.description = "A meaningful description" | ||
e.begin = datetime.fromisoformat('2022-06-06T12:05:23+02:00') | ||
e.end = datetime.fromisoformat('2022-06-06T13:05:23+02:00') | ||
c.events.append(e) | ||
c | ||
# Calendar(extra=Container('VCALENDAR', []), extra_params={}, version='2.0', prodid='ics.py 0.8.0-dev - http://git.io/lLljaA', scale=None, method=None, events=[Event(extra=Container('VEVENT', []), extra_params={}, timespan=EventTimespan(begin_time=datetime.datetime(2022, 6, 6, 12, 5, 23, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200))), end_time=None, duration=None, precision='second'), summary=None, uid='[email protected]', description=None, location=None, url=None, status=None, created=None, last_modified=None, dtstamp=datetime.datetime(2022, 6, 6, 19, 28, 14, 575558, tzinfo=Timezone.from_tzid('UTC')), alarms=[], attach=[], classification=None, transparent=None, organizer=None, geo=None, attendees=[], categories=[])], todos=[]) | ||
with open('my.ics', 'w') as f: | ||
f.write(c.serialize()) | ||
More examples are available in the | ||
`documentation <http://icspy.readthedocs.org/>`_. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,53 +12,120 @@ Quickstart | |
:local: | ||
|
||
|
||
|
||
Importing a Calendar from a File | ||
-------------------------------- | ||
Conventions | ||
----------- | ||
|
||
.. code-block:: python | ||
from ics import Calendar | ||
import requests | ||
c = ics.Calendar() | ||
e = ics.Event() | ||
a = ics.Attendee() | ||
url = "https://urlab.be/events/urlab.ics" | ||
c = Calendar(requests.get(url).text) | ||
Importing a Calendar from a URL | ||
-------------------------------- | ||
|
||
c | ||
# <Calendar with 118 events and 0 todo> | ||
c.events | ||
# {<Event 'Visite de "Fab Bike"' begin:2016-06-21T15:00:00+00:00 end:2016-06-21T17:00:00+00:00>, | ||
# <Event 'Le lundi de l'embarqué: Adventure in Espressif Non OS SDK edition' begin:2018-02-19T17:00:00+00:00 end:2018-02-19T22:00:00+00:00>, | ||
# ...} | ||
e = list(c.timeline)[0] | ||
"Event '{}' started {}".format(e.name, e.begin.humanize()) | ||
# "Event 'Workshop Git' started 2 years ago" | ||
Download the calender file through requests or any other library. | ||
Error handling is recommended. | ||
|
||
.. code-block:: python | ||
from ics import Calendar | ||
import requests | ||
url = "https://urlab.be/events/urlab.ics" | ||
try: | ||
c = Calendar(requests.get(url).text) | ||
except Exception as e: | ||
print(e) | ||
print(c) | ||
# <Calendar with 118 events and 0 todo> | ||
print(c.events[2]) | ||
# <Event 'TechMardi 20/2015' begin: 2015-12-08 17:30:00+00:00 fixed end: 2015-12-08 22:00:00+00:00 duration: 4:30:00> | ||
e = list(c.timeline)[0] | ||
print("Event '{}' started {}".format(e.summary, e.begin)) | ||
# Event 'Workshop Git' started 2015-11-16 17:30:00+00:00 | ||
Creating a new Calendar and Add Events | ||
-------------------------------------- | ||
|
||
:class:`Calendar` objects each represent an unique RFC 5545 iCalendar. They contain :class:`Event`, :class:`Todo` and :class:`Timeline` iterators. | ||
|
||
Time and date are represented as :class:`datetime` objects and can be expressed as ISO 8601 strings or with the class constructor. | ||
|
||
.. code-block:: python | ||
from ics import Calendar, Event | ||
c = Calendar() | ||
e = Event() | ||
e.name = "My cool event" | ||
e.begin = '2014-01-01 00:00:00' | ||
c.events.add(e) | ||
c.events | ||
# {<Event 'My cool event' begin:2014-01-01 00:00:00 end:2014-01-01 00:00:01>} | ||
from datetime import datetime, timezone, timedelta | ||
from ics import Calendar, Event | ||
c = Calendar() | ||
e = Event() | ||
e.summary = "My cool event" | ||
e.description = "A meaningful description" | ||
e.begin = datetime.fromisoformat('2022-06-06T12:05:23+02:00') | ||
e.end = datetime(year=2022, month=6, day=6, hour=12, minute=5, second=23, tzinfo=timezone(timedelta(seconds=7200))) | ||
c.events.append(e) | ||
c | ||
# Calendar(extra=Container('VCALENDAR', []), extra_params={}, version='2.0', prodid='ics.py 0.8.0-dev - http://git.io/lLljaA', scale=None, method=None, events=[Event(extra=Container('VEVENT', []), extra_params={}, timespan=EventTimespan(begin_time=datetime.datetime(2022, 6, 6, 12, 5, 23, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200))), end_time=datetime.datetime(2022, 6, 6, 12, 5, 23, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200))), duration=None, precision='second'), summary='My cool event', uid='[email protected]', description='A meaningful description', location=None, url=None, status=None, created=None, last_modified=None, dtstamp=datetime.datetime(2022, 6, 30, 12, 41, 24, 624188, tzinfo=Timezone.from_tzid('UTC')), alarms=[], attach=[], classification=None, transparent=None, organizer=None, geo=None, attendees=[], categories=[])], todos=[]) | ||
Get event datetime object details | ||
--------------------------------- | ||
|
||
.. code-block:: python | ||
e.cmp_tuple() | ||
# (datetime.datetime(2022, 6, 6, 12, 5, 23, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200))), datetime.datetime(2022, 6, 6, 13, 5, 23, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200))), 'My cool event') | ||
Converting to all-day event | ||
--------------------------- | ||
|
||
Transforms event to a rounded-up all-day event. | ||
|
||
.. code-block:: python | ||
e.cmp_tuple() | ||
# (datetime.datetime(2022, 6, 6, 12, 5, 23, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200))), datetime.datetime(2022, 6, 6, 13, 5, 23, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200))), 'My cool event') | ||
e.make_all_day() | ||
e.cmp_tuple() | ||
# (datetime.datetime(2022, 6, 6, 0, 0, tzinfo=tzlocal()), datetime.datetime(2022, 6, 7, 0, 0, tzinfo=tzlocal()), 'My cool event') | ||
Exporting a Calendar to a File | ||
Exporting a calendar to a file | ||
------------------------------ | ||
|
||
.. code-block:: python | ||
with open('my.ics', 'w') as f: | ||
f.write(c) | ||
# And it's done ! | ||
with open('my.ics', 'w') as f: | ||
f.write(c.serialize()) | ||
Managing attendees | ||
------------------ | ||
|
||
* Adding attendees | ||
|
||
.. code-block:: python | ||
from ics import Attendee | ||
a = Attendee('[email protected]') | ||
e.add_attendee(a) | ||
e.attendees | ||
# [Attendee(email='[email protected]', extra={})] | ||
* Modifying attendees, find all possible attributes and values in :class:`Attendee` | ||
|
||
.. code-block:: python | ||
e.attendees | ||
# [Attendee(email='[email protected]', extra={})] | ||
e.attendees[0].common_name = 'ALL' | ||
e.attendees | ||
# [Attendee(email='[email protected]', extra={'CN': ['ALL']})] | ||
* Removing attendees | ||
|
||
.. code-block:: python | ||
# iCalendar-formatted data is also available in a string | ||
str(c) | ||
# 'BEGIN:VCALENDAR\nPRODID:... | ||
e.attendees | ||
# [Attendee(email='[email protected]', extra={'CN': ['ALL']})] | ||
del e.attendees[0] | ||
e.attendees | ||
# [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.