Code cleanup, class naming improvements
This commit is contained in:
parent
33520a23fe
commit
c4bb24bef9
@ -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
|
||||
|
@ -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 = [{
|
||||
@ -139,9 +139,11 @@ class icalendar:
|
||||
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()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
"""
|
||||
@ -166,7 +166,7 @@ class calendar(inkycal_module):
|
||||
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:
|
||||
@ -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()
|
||||
|
@ -18,11 +18,11 @@ 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):
|
||||
@ -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
|
||||
|
@ -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,10 +20,10 @@ 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
|
||||
"""
|
||||
|
||||
@ -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!)
|
||||
|
Loading…
Reference in New Issue
Block a user