X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;ds=inline;f=gcal_renderer.py;h=31f9724d716d4c4d1da74825ef1dd889f6939f48;hb=1d6c45c8350ba6e5cb7a9fdc30d0663667ded6d4;hp=19b818d8ad3309890eff6ef0d7f7b4b21ba63aed;hpb=6b8d4eeb7153617221f822a243a117f0bcab07bf;p=kiosk.git diff --git a/gcal_renderer.py b/gcal_renderer.py index 19b818d..31f9724 100644 --- a/gcal_renderer.py +++ b/gcal_renderer.py @@ -13,7 +13,7 @@ from dateutil.parser import parse import gdata_oauth import pytz -import constants +import kiosk_constants import file_writer import globals import renderer @@ -50,11 +50,11 @@ class gcal_renderer(renderer.abstaining_renderer): calendar: str, ) -> None: if start_time is None: - assert(end_time is None) + assert end_time is None else: - assert(isinstance(start_time, datetime.datetime)) + assert isinstance(start_time, datetime.datetime) if end_time is not None: - assert(isinstance(end_time, datetime.datetime)) + assert isinstance(end_time, datetime.datetime) self.start_time = start_time self.end_time = end_time self.summary = summary @@ -74,10 +74,10 @@ class gcal_renderer(renderer.abstaining_renderer): def __eq__(self, that) -> bool: return ( - self.start_time == that.start_time and - self.end_time == that.end_time and - self.summary == that.summary and - self.calendar == that.calendar + self.start_time == that.start_time + and self.end_time == that.end_time + and self.summary == that.summary + and self.calendar == that.calendar ) def __repr__(self) -> str: @@ -93,32 +93,24 @@ class gcal_renderer(renderer.abstaining_renderer): if self.start_time is None: return "None" elif ( - self.start_time.hour == 0 and - self.start_time.minute == 0 and - self.start_time.second == 0 + self.start_time.hour == 0 + and self.start_time.minute == 0 + and self.start_time.second == 0 ): if self.start_time.year == now.year: - return datetime.datetime.strftime( - self.start_time, - "%a %b %d" - ) + return datetime.datetime.strftime(self.start_time, "%a %b %d") else: - return datetime.datetime.strftime( - self.start_time, - "%a %b %d, %Y" - ) + return datetime.datetime.strftime(self.start_time, "%a %b %d, %Y") else: dt = self.start_time zone = dt.tzinfo - local_dt = dt.replace(tzinfo=zone).astimezone(tz=pytz.timezone('US/Pacific')) + local_dt = dt.replace(tzinfo=zone).astimezone( + tz=pytz.timezone("US/Pacific") + ) if local_dt.year == now.year: - return datetime.datetime.strftime( - local_dt, "%a %b %d %I:%M%p" - ) + return datetime.datetime.strftime(local_dt, "%a %b %d %I:%M%p") else: - return datetime.datetime.strftime( - local_dt, "%a %b %d, %Y %I:%M%p" - ) + return datetime.datetime.strftime(local_dt, "%a %b %d, %Y %I:%M%p") def __init__( self, name_to_timeout_dict: Dict[str, int], oauth: gdata_oauth.OAuth @@ -133,7 +125,7 @@ class gcal_renderer(renderer.abstaining_renderer): return "gcal" def periodic_render(self, key: str) -> bool: - logger.debug('called for "%s"' % key) + logger.debug(f'called for "{key}"') if key == "Render Upcoming Events": return self.render_upcoming_events() elif key == "Look For Triggered Events": @@ -156,18 +148,20 @@ class gcal_renderer(renderer.abstaining_renderer): if isinstance(date, datetime.datetime): return date elif isinstance(date, dict): - if 'dateTime' in date: - d = date['dateTime'] + if "dateTime" in date: + d = date["dateTime"] dt = parse(d) if dt.tzinfo is None: - dt = dt.replace(tzinfo=None).astimezone(tz=pytz.timezone('US/Pacific')) + dt = dt.replace(tzinfo=None).astimezone( + tz=pytz.timezone("US/Pacific") + ) return dt - elif 'date' in date: - d = date['date'] - dt = datetime.datetime.strptime(d, '%Y-%m-%d') - dt = dt.replace(tzinfo=None).astimezone(tz=pytz.timezone('US/Pacific')) + elif "date" in date: + d = date["date"] + dt = datetime.datetime.strptime(d, "%Y-%m-%d") + dt = dt.replace(tzinfo=None).astimezone(tz=pytz.timezone("US/Pacific")) return dt - print(f'Not sure what to do with this {date} ({type(date)}), help?!') + print(f"Not sure what to do with this {date} ({type(date)}), help?!") return None def get_events_from_interesting_calendars( @@ -182,9 +176,7 @@ class gcal_renderer(renderer.abstaining_renderer): ) for calendar in calendar_list["items"]: if calendar["summary"] in gcal_renderer.calendar_whitelist: - logger.debug( - f"{calendar['summary']} is an interesting calendar..." - ) + logger.debug(f"{calendar['summary']} is an interesting calendar...") events = ( self.client.events() .list( @@ -204,7 +196,7 @@ class gcal_renderer(renderer.abstaining_renderer): f" ... event '{summary}' ({event['start']} ({start}) to {event['end']} ({end})" ) if start is not None and end is not None: - logger.debug(f' ... adding {summary} to sortable_events') + logger.debug(f" ... adding {summary} to sortable_events") sortable_events.append( gcal_renderer.comparable_event( start, end, summary, calendar["summary"] @@ -215,7 +207,9 @@ class gcal_renderer(renderer.abstaining_renderer): or "Holidays" in calendar["summary"] or "Countdown" in summary ): - logger.debug(f" ... adding {summary} to countdown_events") + logger.debug( + f" ... adding {summary} to countdown_events" + ) countdown_events.append( gcal_renderer.comparable_event( start, end, summary, calendar["summary"] @@ -230,6 +224,7 @@ class gcal_renderer(renderer.abstaining_renderer): (time_min, time_max) = self.get_min_max_timewindow() try: # Populate the "Upcoming Events" page. + logger.debug("Rendering the Upcoming Events page...") ( self.sortable_events, self.countdown_events, @@ -237,7 +232,7 @@ class gcal_renderer(renderer.abstaining_renderer): self.sortable_events.sort() with file_writer.file_writer("gcal_3_86400.html") as f: f.write( -f""" + """