From 0c9e76e23d97b38cb862bacbde75e4905475888d Mon Sep 17 00:00:00 2001 From: Marius Cramer Date: Mon, 18 May 2020 20:42:13 +0200 Subject: [PATCH 1/2] add documentation for Google Calendar integration setup --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5c6a9aa..95c0cf0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # Managing LaTeX lecture notes -This repository complements my [third blog post about my note taking setup](https://castel.dev/post/lecture-notes-3). +This repository complements my [third blog post about my note taking +setup](https://castel.dev/post/lecture-notes-3). -To get the calendar script working, follow step 1 and 2 of the [Google Calendar Python Quickstart](https://developers.google.com/calendar/quickstart/python), and place `credentials.json` in the `scripts` directory. + +## Setup Google Calendar integration + +To get the calendar script (`countdown.py`) working, follow step 1 and 2 of the [Google +Calendar Python Quickstart](https://developers.google.com/calendar/quickstart/python), and +place `credentials.json` in the `scripts` directory. +Then open `config.py` and edit the `ROOT` as well as the `USERCALENDARID` +variables to your own needs. From 79849610ab218484393dca6822c6568303633d0c Mon Sep 17 00:00:00 2001 From: Marius Cramer Date: Mon, 18 May 2020 20:42:34 +0200 Subject: [PATCH 2/2] link calendarId to config.py to ease user setup --- scripts/config.py | 7 +++++++ scripts/countdown.py | 9 +++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/config.py b/scripts/config.py index aadc344..3db98e0 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -4,6 +4,13 @@ from pathlib import Path def get_week(d=datetime.today()): return (int(d.strftime("%W")) + 52 - 5) % 52 +# 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 +# the relevant calendar and scrolling down to Calendar ID) probably looks like +# xxxxxxxxxxxxxxxxxxxxxxxxxg@group.calendar.google.com +# example: +# USERCALENDARID = 'xxxxxxxxxxxxxxxxxxxxxxxxxg@group.calendar.google.com' +USERCALENDARID = 'primary' CURRENT_COURSE_SYMLINK = Path('~/current_course').expanduser() CURRENT_COURSE_ROOT = CURRENT_COURSE_SYMLINK.resolve() CURRENT_COURSE_WATCH_FILE = Path('/tmp/current_course').resolve() diff --git a/scripts/countdown.py b/scripts/countdown.py index 5a604c3..dfc26df 100755 --- a/scripts/countdown.py +++ b/scripts/countdown.py @@ -21,6 +21,7 @@ from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request from courses import Courses +from config import USERCALENDARID courses = Courses() @@ -58,7 +59,7 @@ def join(*args): def truncate(string, length): ellipsis = ' ...' if len(string) < length: - return string + return string return string[:length - len(ellipsis)] + ellipsis def summary(text): @@ -186,7 +187,7 @@ def main(): if 'dateTime' in event['start'] ] - events = get_events('primary') + events = get_events(userCalendarId) # events = get_events('primary') + get_events('school-calendar@import.calendar.google.com') print('Done') @@ -197,7 +198,7 @@ def main(): print(text(events, now)) if now < evening: scheduler.enter(DELAY, 1, print_message) - + for event in events: # absolute entry, priority 1 scheduler.enterabs(event['start'].timestamp(), 1, activate_course, argument=(event, )) @@ -205,7 +206,7 @@ def main(): # Immediate, priority 1 scheduler.enter(0, 1, print_message) scheduler.run() - + def wait_for_internet_connection(url, timeout=1): while True: