Update inkycal_icalendar.py
This commit is contained in:
parent
d734f36b7b
commit
fe1a688def
@ -2,7 +2,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
iCalendar (parsing) module for Inky-Calendar Project
|
iCalendar (parsing) module for Inky-Calendar Project
|
||||||
|
|
||||||
Copyright by aceisace
|
Copyright by aceisace
|
||||||
"""
|
"""
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
@ -11,10 +10,12 @@ from settings import ical_urls
|
|||||||
import arrow
|
import arrow
|
||||||
from ics import Calendar
|
from ics import Calendar
|
||||||
|
|
||||||
print_events = True
|
print_events = False
|
||||||
|
style = 'DD MMM YY HH:mm' #D MMM YY HH:mm
|
||||||
|
|
||||||
"""Set timelines for filtering upcoming events"""
|
"""Set timelines for filtering upcoming events"""
|
||||||
now = arrow.now(tz=get_tz())
|
now = arrow.now(tz=get_tz())
|
||||||
|
beginning_of_month = now.replace(days= - now.day +1)
|
||||||
near_future = now.replace(days= 30)
|
near_future = now.replace(days= 30)
|
||||||
further_future = now.replace(days=40)
|
further_future = now.replace(days=40)
|
||||||
|
|
||||||
@ -22,9 +23,9 @@ further_future = now.replace(days=40)
|
|||||||
calendars = [Calendar(fix_ical(url)) for url in ical_urls]
|
calendars = [Calendar(fix_ical(url)) for url in ical_urls]
|
||||||
|
|
||||||
"""Filter any upcoming events from all iCalendars and add them to a list"""
|
"""Filter any upcoming events from all iCalendars and add them to a list"""
|
||||||
upcoming_events = []
|
upcoming_events = [events for ical in calendars for events in ical.events
|
||||||
upcoming_events += [events for ical in calendars for events in ical.events
|
if beginning_of_month <= events.end <= further_future or
|
||||||
if now <= events.end <= further_future or now <= events.begin <= near_future]
|
beginning_of_month <= events.begin <= near_future]
|
||||||
|
|
||||||
"""Sort events according to their beginning date"""
|
"""Sort events according to their beginning date"""
|
||||||
def sort_dates(event):
|
def sort_dates(event):
|
||||||
@ -40,14 +41,10 @@ for events in upcoming_events:
|
|||||||
this one, copy the list or the contents to another one."""
|
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) # Print all events. Might look a bit messy
|
||||||
|
|
||||||
|
|
||||||
"""Print upcoming events in a more appealing way"""
|
"""Print upcoming events in a more appealing way"""
|
||||||
if print_events == True:
|
if print_events == True and upcoming_events:
|
||||||
style = 'DD MMM YY HH:mm' #D MMM YY HH:mm
|
|
||||||
if upcoming_events:
|
|
||||||
line_width = max(len(i.name) for i in 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} |'.format(events.name,
|
print('{0} {1} | {2} | {3} | All day ='.format(events.name,
|
||||||
' '* (line_width - len(events.name)), events.begin.format(style),
|
' '* (line_width - len(events.name)), events.begin.format(style),
|
||||||
events.end.format(style)), events.all_day)
|
events.end.format(style)), events.all_day)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user