Welcome to iCalEvents’s documentation!¶
Simple Python 3 library to download, parse and query iCal sources.
Usage¶
iCloud:¶
from icalevents.icalevents import events
es = events(<iCloud URL>, fix_apple=True)
Google:¶
from icalevents.icalevents import events
es = events(<Google Calendar URL>)
Example¶
see main.py
from icalevents.icalevents import events_async, latest_events, all_done
from time import sleep
if __name__ == '__main__':
keys = []
with open('calendars.txt', mode='r', encoding='utf-8') as f:
counter = 1
while True:
line = f.readline()
if not line:
break
name, url = line.split(maxsplit=1)
name = name.strip()
url = url.strip()
fix_apple = False
if name == 'icloud':
fix_apple = True
key = "req_%d" % counter
counter += 1
keys.append(key)
events_async(key, url, fix_apple=fix_apple)
while keys:
print("%d request running." % len(keys))
for k in keys[:]:
if all_done(k):
print("Request %s finished." % k)
keys.remove(k)
es = latest_events(k)
for e in es:
print(e)
sleep(2)
API¶
Module contents¶
iCalEvents search all events occurring in a given time frame in an iCal file.
Submodules¶
icalevents.icaldownload module¶
Downloads an iCal url or reads an iCal file.
- class icalevents.icaldownload.ICalDownload(http=None, encoding='utf-8')¶
Bases:
object
Downloads or reads and decodes iCal sources.
- data_from_file(file, apple_fix=False)¶
Read iCal data from file.
- Parameters
file – file to read
apple_fix – fix wrong Apple tzdata in iCal
- Returns
decoded (and fixed) iCal data
- data_from_string(string_content, apple_fix=False)¶
- data_from_url(url, apple_fix=False)¶
Download iCal data from URL.
- Parameters
url – URL to download
apple_fix – fix Apple bugs (protocol type and tzdata in iCal)
- Returns
decoded (and fixed) iCal data
- decode(content, apple_fix=False)¶
Decode content using the set charset.
- Parameters
content – content do decode
apple_fix – fix Apple txdata bug
- Returns
decoded (and fixed) content
- icalevents.icaldownload.apple_data_fix(content)¶
Fix Apple tzdata bug.
- Parameters
content – content to fix
- Returns
fixed content
- icalevents.icaldownload.apple_url_fix(url)¶
Fix Apple URL.
- Parameters
url – URL to fix
- Returns
fixed URL
icalevents.icalevents module¶
icalevents.icalparser module¶
Parse iCal data to Events.
- class icalevents.icalparser.Event¶
Bases:
object
Represents one event (occurrence in case of reoccurring events).
- astimezone(tzinfo)¶
- copy_to(new_start=None, uid=None)¶
Create a new event equal to this with new start date.
- Parameters
new_start – new start date
uid – UID of new event
- Returns
new event
- time_left(time=None)¶
timedelta form now to event.
- Returns
timedelta from now
- icalevents.icalparser.create_event(component, utc_default)¶
Create an event from its iCal representation.
- Parameters
component – iCal component
- Returns
event
- icalevents.icalparser.encode(value: Optional[vText]) Optional[str] ¶
- icalevents.icalparser.extract_exdates(component)¶
Compile a list of all exception dates stored with a component.
- Parameters
component – icalendar iCal component
- Returns
list of exception dates
- icalevents.icalparser.get_timezone(tz_name)¶
- icalevents.icalparser.now()¶
Get current time.
- Returns
now as datetime with timezone
- icalevents.icalparser.parse_events(content, start=None, end=None, default_span=datetime.timedelta(days=7), tzinfo=None, sort=False, strict=False)¶
Query the events occurring in a given time range.
- Parameters
content – iCal URL/file content as String
start – start date for search, default today (in UTC format)
end – end date for search (in UTC format)
default_span – default query length (one week)
- Returns
events as list
- icalevents.icalparser.parse_rrule(component)¶
Extract a dateutil.rrule object from an icalendar component. Also includes the component’s dtstart and exdate properties. The rdate and exrule properties are not yet supported.
- Parameters
component – icalendar component
- Returns
extracted rrule or rruleset or None