Update inkycal_icalendar.py
This commit is contained in:
parent
36d553660c
commit
6b7366924a
@ -13,38 +13,42 @@ from ics import Calendar
|
|||||||
print_events = False
|
print_events = False
|
||||||
style = 'DD MMM YY HH:mm'
|
style = 'DD MMM YY HH:mm'
|
||||||
|
|
||||||
"""Set timelines for filtering upcoming events"""
|
|
||||||
now = arrow.now(tz=get_tz())
|
|
||||||
beginning_of_month = now.replace(days= - now.day +1)
|
|
||||||
near_future = now.replace(days= 30)
|
|
||||||
further_future = now.replace(days=40)
|
|
||||||
|
|
||||||
"""Parse the iCalendars from the urls, fixing some known errors with ics"""
|
def fetch_events():
|
||||||
calendars = [Calendar(fix_ical(url)) for url in ical_urls]
|
"""Set timelines for filtering upcoming events"""
|
||||||
|
now = arrow.now(tz=get_tz())
|
||||||
|
beginning_of_month = now.replace(days= - now.day +1)
|
||||||
|
near_future = now.replace(days= 30)
|
||||||
|
further_future = now.replace(days=40)
|
||||||
|
|
||||||
"""Filter any upcoming events from all iCalendars and add them to a list"""
|
"""Parse the iCalendars from the urls, fixing some known errors with ics"""
|
||||||
upcoming_events = [events for ical in calendars for events in ical.events
|
calendars = [Calendar(fix_ical(url)) for url in ical_urls]
|
||||||
if beginning_of_month <= events.end <= further_future or
|
|
||||||
beginning_of_month <= events.begin <= near_future]
|
|
||||||
|
|
||||||
"""Sort events according to their beginning date"""
|
"""Filter any upcoming events from all iCalendars and add them to a list"""
|
||||||
def sort_dates(event):
|
upcoming_events = [events for ical in calendars for events in ical.events
|
||||||
return event.begin
|
if beginning_of_month <= events.end <= further_future or
|
||||||
upcoming_events.sort(key=sort_dates)
|
beginning_of_month <= events.begin <= near_future]
|
||||||
|
|
||||||
"""Multiday events are displayed incorrectly; fix that"""
|
"""Sort events according to their beginning date"""
|
||||||
for events in upcoming_events:
|
def sort_dates(event):
|
||||||
if events.all_day and events.duration.days > 1:
|
return event.begin
|
||||||
events.end = events.end.replace(days=-2)
|
upcoming_events.sort(key=sort_dates)
|
||||||
|
|
||||||
""" The list upcoming_events should not be modified. If you need the data from
|
"""Multiday events are displayed incorrectly; fix that"""
|
||||||
this one, copy the list or the contents to another one."""
|
|
||||||
#print(upcoming_events) # Print all events. Might look a bit messy
|
|
||||||
|
|
||||||
"""Print upcoming events in a more appealing way"""
|
|
||||||
if print_events == True and upcoming_events:
|
|
||||||
line_width = max(len(i.name) for i in upcoming_events)
|
|
||||||
for events in upcoming_events:
|
for events in upcoming_events:
|
||||||
print('{0} {1} | {2} | {3} | All day ='.format(events.name,
|
if events.all_day and events.duration.days > 1:
|
||||||
' '* (line_width - len(events.name)), events.begin.format(style),
|
events.end = events.end.replace(days=-2)
|
||||||
events.end.format(style)), events.all_day)
|
|
||||||
|
""" The list upcoming_events should not be modified. If you need the data from
|
||||||
|
this one, copy the list or the contents to another one."""
|
||||||
|
#print(upcoming_events) # Print all events. Might look a bit messy
|
||||||
|
|
||||||
|
"""Print upcoming events in a more appealing way"""
|
||||||
|
if print_events == True and upcoming_events:
|
||||||
|
line_width = max(len(i.name) for i in upcoming_events)
|
||||||
|
for events in upcoming_events:
|
||||||
|
print('{0} {1} | {2} | {3} | All day ='.format(events.name,
|
||||||
|
' '* (line_width - len(events.name)), events.begin.format(style),
|
||||||
|
events.end.format(style)), events.all_day)
|
||||||
|
|
||||||
|
return upcoming_events
|
||||||
|
Loading…
Reference in New Issue
Block a user