make timezone a setting in config.py. Translate countdown file to use english for specifying next lectures etc.

This commit is contained in:
Maximilian Keßler 2021-09-17 12:04:33 +02:00
parent fc7c77e5d7
commit 2f967f57cc
2 changed files with 16 additions and 15 deletions

View file

@ -1,5 +1,5 @@
from pathlib import Path from pathlib import Path
import pytz
# default is 'primary', if you are using a separate calendar for your course schedule, # default is 'primary', if you are using a separate calendar for your course schedule,
# your calendarId (which you can find by going to your Google Calendar settings, selecting # your calendarId (which you can find by going to your Google Calendar settings, selecting
# the relevant calendar and scrolling down to Calendar ID) probably looks like # the relevant calendar and scrolling down to Calendar ID) probably looks like
@ -23,3 +23,4 @@ DEFAULT_NEW_LECTURE_TITLE = 'Untitled'
DEFAULT_LECTURE_SEARCH_REGEX = r'lecture.*({\d*})?{(.*?)}{(.*)}' DEFAULT_LECTURE_SEARCH_REGEX = r'lecture.*({\d*})?{(.*?)}{(.*)}'
DEFAULT_IMPORT_INDENTATION = 4 DEFAULT_IMPORT_INDENTATION = 4
FALLBACK_COURSE_INFO_FILE = Path('fallback.yaml').resolve() FALLBACK_COURSE_INFO_FILE = Path('fallback.yaml').resolve()
TIMEZONE = pytz.timezone('CET')

View file

@ -21,7 +21,7 @@ from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request from google.auth.transport.requests import Request
from courses import Courses from courses import Courses
from config import USERCALENDARID from config import USERCALENDARID, TIMEZONE
courses = Courses() courses = Courses()
@ -72,7 +72,7 @@ def formatdd(begin, end):
minutes = math.ceil((end - begin).seconds / 60) minutes = math.ceil((end - begin).seconds / 60)
if minutes == 1: if minutes == 1:
return '1 minuut' return '1 minute'
if minutes < 60: if minutes < 60:
return f'{minutes} min' return f'{minutes} min'
@ -81,9 +81,9 @@ def formatdd(begin, end):
rest_minutes = minutes % 60 rest_minutes = minutes % 60
if hours > 5 or rest_minutes == 0: if hours > 5 or rest_minutes == 0:
return f'{hours} uur' return f'{hours} hours'
return '{}:{:02d} uur'.format(hours, rest_minutes) return '{}:{:02d} h'.format(hours, rest_minutes)
def location(text): def location(text):
if not text: if not text:
@ -103,7 +103,7 @@ def text(events, now):
if nxt: if nxt:
return join( return join(
summary(nxt['summary']), summary(nxt['summary']),
gray('over'), gray('in'),
formatdd(now, nxt['start']), formatdd(now, nxt['start']),
location(nxt['location']) location(nxt['location'])
) )
@ -111,24 +111,24 @@ def text(events, now):
nxt = next((e for e in events if e['start'] >= current['end']), None) nxt = next((e for e in events if e['start'] >= current['end']), None)
if not nxt: if not nxt:
return join(gray('Einde over'), formatdd(now, current['end']) + '!') return join(gray('Ends in'), formatdd(now, current['end']) + '!')
if current['end'] == nxt['start']: if current['end'] == nxt['start']:
return join( return join(
gray('Einde over'), gray('Ends in'),
formatdd(now, current['end']) + gray('.'), formatdd(now, current['end']) + gray('.'),
gray('Hierna'), gray('Afterwards'),
summary(nxt['summary']), summary(nxt['summary']),
location(nxt['location']) location(nxt['location'])
) )
return join( return join(
gray('Einde over'), gray('Ends in'),
formatdd(now, current['end']) + gray('.'), formatdd(now, current['end']) + gray('.'),
gray('Hierna'), gray('Afterwards'),
summary(nxt['summary']), summary(nxt['summary']),
location(nxt['location']), location(nxt['location']),
gray('na een pauze van'), gray('after a break of'),
formatdd(current['end'], nxt['start']) formatdd(current['end'], nxt['start'])
) )
@ -160,7 +160,7 @@ def main():
print('Authenticated') print('Authenticated')
# Call the Calendar API # Call the Calendar API
now = datetime.datetime.now(tz=TZ) now = datetime.datetime.now(tz=TIMEZONE)
morning = now.replace(hour=6, minute=0, microsecond=0) morning = now.replace(hour=6, minute=0, microsecond=0)
evening= now.replace(hour=23, minute=59, microsecond=0) evening= now.replace(hour=23, minute=59, microsecond=0)
@ -187,14 +187,14 @@ def main():
if 'dateTime' in event['start'] if 'dateTime' in event['start']
] ]
events = get_events(userCalendarId) events = get_events(USERCALENDARID)
# events = get_events('primary') + get_events('school-calendar@import.calendar.google.com') # events = get_events('primary') + get_events('school-calendar@import.calendar.google.com')
print('Done') print('Done')
DELAY = 60 DELAY = 60
def print_message(): def print_message():
now = datetime.datetime.now(tz=TZ) now = datetime.datetime.now(tz=TIMEZONE)
print(text(events, now)) print(text(events, now))
if now < evening: if now < evening:
scheduler.enter(DELAY, 1, print_message) scheduler.enter(DELAY, 1, print_message)