diff --git a/inkycal/modules/__init__.py b/inkycal/modules/__init__.py index 8ad6905..fec80e7 100644 --- a/inkycal/modules/__init__.py +++ b/inkycal/modules/__init__.py @@ -1,4 +1,5 @@ -##from .inkycal_agenda import agenda -##from .inkycal_calendar import calendar -##from .inkycal_weather import weather -##from .inkycal_rss import rss +from .inkycal_agenda import Agenda +from .inkycal_calendar import Calendar +from .inkycal_weather import Weather +from .inkycal_rss import RSS +#from .inkycal_image import Image diff --git a/inkycal/modules/ical_parser.py b/inkycal/modules/ical_parser.py index c0f9c90..5fab105 100644 --- a/inkycal/modules/ical_parser.py +++ b/inkycal/modules/ical_parser.py @@ -16,7 +16,7 @@ Copyright by aceisace import arrow from urllib.request import urlopen import logging -import time # timezone, timing speed of execution +import time import os try: @@ -36,7 +36,7 @@ filename = os.path.basename(__file__).split('.py')[0] logger = logging.getLogger(filename) logger.setLevel(level=logging.INFO) -class icalendar: +class iCalendar: """iCalendar parsing moudule for inkycal. Parses events from given iCalendar URLs / paths""" @@ -108,7 +108,7 @@ class icalendar: t_start = timeline_start t_end = timeline_end else: - raise Exception ('Please input a valid arrow object!') + raise Exception('Please input a valid arrow (time) object!') # parse non-recurring events events = [{ @@ -135,13 +135,15 @@ class icalendar: # Parse recurring events recurring_events = [recurring_ical_events.of(ical).between( fmt(t_start),fmt(t_end)) for ical in self.icalendars] - + re_events = [{ 'title':events.get('SUMMARY').lstrip(), 'begin':arrow.get(events.get('DTSTART').dt).to(timezone - if arrow.get(events.get('dtstart').dt).format('HH:mm') != '00:00' else 'UTC'), + if arrow.get(events.get('dtstart').dt).format('HH:mm') != '00:00' + else 'UTC'), 'end':arrow.get(events.get("DTEND").dt).to(timezone - if arrow.get(events.get('dtstart').dt).format('HH:mm') != '00:00' else 'UTC') + if arrow.get(events.get('dtstart').dt).format('HH:mm') != '00:00' + else 'UTC') } for ical in recurring_events for events in ical] # if any recurring events were found, add them to parsed_events @@ -214,20 +216,3 @@ class icalendar: if __name__ == '__main__': print('running {0} in standalone mode'.format(filename)) - - -urls = [ - # Default calendar - 'https://calendar.google.com/calendar/ical/en.usa%23holiday%40group.v.calendar.google.com/public/basic.ics', - # inkycal debug calendar - 'https://calendar.google.com/calendar/ical/6nqv871neid5l0t7hgk6jgr24c%40group.calendar.google.com/private-c9ab692c99fb55360cbbc28bf8dedb3a/basic.ics' - ] - -##a = icalendar() -##a.load_url(urls) -##a.get_events(arrow.now(), arrow.now().shift(weeks=4), timezone = a.get_system_tz()) -##a.show_events() - - - - diff --git a/inkycal/modules/inkycal_agenda.py b/inkycal/modules/inkycal_agenda.py index e6c614b..ffea504 100644 --- a/inkycal/modules/inkycal_agenda.py +++ b/inkycal/modules/inkycal_agenda.py @@ -7,17 +7,17 @@ Copyright by aceisace from inkycal.modules.template import inkycal_module from inkycal.custom import * -from inkycal.modules.ical_parser import icalendar +from inkycal.modules.ical_parser import iCalendar import calendar as cal import arrow filename = os.path.basename(__file__).split('.py')[0] logger = logging.getLogger(filename) -logger.setLevel(level=logging.INFO) +logger.setLevel(level=logging.ERROR) -class agenda(inkycal_module): +class Agenda(inkycal_module): """Agenda class Create agenda and show events from given icalendars """ @@ -94,7 +94,8 @@ class agenda(inkycal_module): for _ in range(max_lines)] # Load icalendar from config - parser = icalendar() + self.ical = iCalendar() + parser = self.parser if self.ical_urls: parser.load_url(self.ical_urls) if self.ical_files: @@ -202,7 +203,3 @@ class agenda(inkycal_module): if __name__ == '__main__': print('running {0} in standalone mode'.format(filename)) - -##size = (400, 520) -##config = {'week_starts_on': 'Monday', 'ical_urls': ['https://calendar.google.com/calendar/ical/en.usa%23holiday%40group.v.calendar.google.com/public/basic.ics']} -##a = agenda(size, config).generate_image() diff --git a/inkycal/modules/inkycal_calendar.py b/inkycal/modules/inkycal_calendar.py index 00086df..c9e1269 100644 --- a/inkycal/modules/inkycal_calendar.py +++ b/inkycal/modules/inkycal_calendar.py @@ -12,9 +12,9 @@ import arrow filename = os.path.basename(__file__).split('.py')[0] logger = logging.getLogger(filename) -logger.setLevel(level=logging.INFO) +logger.setLevel(level=logging.ERROR) -class calendar(inkycal_module): +class Calendar(inkycal_module): """Calendar class Create monthly calendar and show events from given icalendars """ @@ -40,10 +40,10 @@ class calendar(inkycal_module): fonts['NotoSans-SemiCondensed'], size = self.fontsize) self.weekstart = self.config['week_starts_on'] self.show_events = True - self.date_format = 'D MMM' # used for dates + self.date_format = 'D MMM' # used for dates self.time_format = "HH:mm" # used for timings self.language = 'en' # Grab from settings file? - + self.timezone = get_system_tz() self.ical_urls = self.config['ical_urls'] self.ical_files = [] @@ -160,13 +160,13 @@ class calendar(inkycal_module): write(icon, (0,0), (icon_width, icon_height), str(now.day), font=self.num_font, fill_height = 0.5, colour='white') im_colour.paste(icon, current_day_pos, icon) - + # If events should be loaded and shown... if self.show_events == True: # import the ical-parser - from inkycal.modules.ical_parser import icalendar + from inkycal.modules.ical_parser import iCalendar # find out how many lines can fit at max in the event section line_spacing = 0 @@ -182,7 +182,9 @@ class calendar(inkycal_module): month_end = arrow.get(now.ceil('month')) # fetch events from given icalendars - parser = icalendar() + self.ical = iCalendar() + parser = self.ical + if self.ical_urls: parser.load_url(self.ical_urls) if self.ical_files: @@ -230,13 +232,13 @@ class calendar(inkycal_module): date_width = int(max([self.font.getsize( events['begin'].format(self.date_format,locale=lang))[0] for events in upcoming_events]) * 1.1) - + time_width = int(max([self.font.getsize( events['begin'].format(self.time_format, locale=lang))[0] for events in upcoming_events]) * 1.1) line_height = self.font.getsize('hg')[1] + line_spacing - + event_width_s = im_width - date_width - time_width event_width_l = im_width - date_width @@ -282,9 +284,3 @@ class calendar(inkycal_module): if __name__ == '__main__': print('running {0} in standalone mode'.format(filename)) - - -##size = (400, 520) -##config = {'week_starts_on': 'Monday', 'ical_urls': ['https://calendar.google.com/calendar/ical/en.usa%23holiday%40group.v.calendar.google.com/public/basic.ics']} -##a = calendar(size, config) -##a.generate_image() diff --git a/inkycal/modules/inkycal_rss.py b/inkycal/modules/inkycal_rss.py index f778bad..51cc2dc 100644 --- a/inkycal/modules/inkycal_rss.py +++ b/inkycal/modules/inkycal_rss.py @@ -18,16 +18,16 @@ except ImportError: filename = os.path.basename(__file__).split('.py')[0] logger = logging.getLogger(filename) -logger.setLevel(level=logging.INFO) +logger.setLevel(level=logging.ERROR) -class rss(inkycal_module): +class RSS(inkycal_module): """RSS class - parses rss feeds from given urls + parses rss/atom feeds from given urls """ def __init__(self, section_size, section_config): """Initialize inkycal_rss module""" - + super().__init__(section_size, section_config) # Module specific parameters @@ -130,20 +130,5 @@ class rss(inkycal_module): im_black.save(images+self.name+'.png', 'PNG') im_colour.save(images+self.name+'_colour.png', 'PNG') - -##def main(): -## print('Main got executed just now~~~~') - - if __name__ == '__main__': print('running {0} in standalone/debug mode'.format(filename)) -##else: -## print(filename, 'imported') -## main() - -##a = rss(size, config) -##a.generate_image() -##size = (384, 160) -##config = {'rss_urls': ['http://feeds.bbci.co.uk/news/world/rss.xml#']} -#config = {'rss_urls': ['http://www.tagesschau.de/xml/atom/']} -#https://www.tagesschau.de/xml/rss2 -> problematic feed diff --git a/inkycal/modules/inkycal_weather.py b/inkycal/modules/inkycal_weather.py index 7ee930e..980f9d7 100644 --- a/inkycal/modules/inkycal_weather.py +++ b/inkycal/modules/inkycal_weather.py @@ -4,12 +4,14 @@ Weather module for Inky-Calendar software. Copyright by aceisace """ + from inkycal.modules.template import inkycal_module from inkycal.custom import * import math, decimal import arrow from locale import getdefaultlocale as sys_locale + try: import pyowm except ImportError: @@ -18,16 +20,16 @@ except ImportError: filename = os.path.basename(__file__).split('.py')[0] logger = logging.getLogger(filename) -logger.setLevel(level=logging.INFO) +logger.setLevel(level=logging.ERROR) -class weather(inkycal_module): - """weather class +class Weather(inkycal_module): + """Weather class parses weather details from openweathermap """ def __init__(self, section_size, section_config): """Initialize inkycal_weather module""" - + super().__init__(section_size, section_config) # Module specific parameters @@ -323,7 +325,7 @@ class weather(inkycal_module): } for key,val in fc_data.items(): - logger.info((key,val)) + logger.debug((key,val)) # Get some current weather details temperature = '{}°'.format(weather.get_temperature(unit=temp_unit)['temp']) @@ -426,10 +428,3 @@ class weather(inkycal_module): if __name__ == '__main__': print('running {0} in standalone mode'.format(filename)) - - -##config = {'api_key': 'secret', 'location': 'Stuttgart, DE'} -##size = (384,80) -##a = weather(size, config) -##a.generate_image() -# Debug Data (not for production use!) diff --git a/inkycal/modules/test.py b/inkycal/modules/test_module.py similarity index 100% rename from inkycal/modules/test.py rename to inkycal/modules/test_module.py