From 50ada1d6d7f57ee7729f9df3e6db55bc611e6d9a Mon Sep 17 00:00:00 2001 From: Ville Ranki Date: Mon, 23 Dec 2019 18:04:45 +0200 Subject: [PATCH] Fix google calendar event sending, fixes #1. Readme updates. --- Dockerfile | 2 +- Pipfile | 3 +++ README.md | 7 ++++--- modules/googlecal.py | 13 +++++++------ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8a8c5d6..4cfe6ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM python:3 WORKDIR /bot RUN pip install pipenv COPY Pipfile . -RUN pipenv install --skip-lock --system +RUN pipenv install --pre --system COPY bot.py . COPY modules modules diff --git a/Pipfile b/Pipfile index 56b8db5..cd8cb38 100644 --- a/Pipfile +++ b/Pipfile @@ -18,3 +18,6 @@ pylint = "*" [requires] python_version = "3.7" + +[pipenv] +allow_prereleases = true diff --git a/README.md b/README.md index 758f32e..1a748e1 100644 --- a/README.md +++ b/README.md @@ -119,12 +119,13 @@ Example: ## Running on host -Run something like: +Run something like (tested on Ubuntu): ``` bash -pip3 install pipenv +sudo apt install python3-pip +sudo pip3 install pipenv pipenv shell -pipenv install +pipenv install --pre MATRIX_USER="@user:matrix.org" MATRIX_ACCESS_TOKEN="MDAxOGxvYlotofcharacters53CgYAYFgo" MATRIX_SERVER="https://matrix.org" JOIN_ON_INVITE=True python3 bot.py ``` diff --git a/modules/googlecal.py b/modules/googlecal.py index 2d2cce0..be8215a 100644 --- a/modules/googlecal.py +++ b/modules/googlecal.py @@ -115,9 +115,10 @@ class MatrixModule: if len(events) == 0: await bot.send_text(room, 'No events found.') - else: - print(f'Found {len(events)} events') - await self.send_events(bot, events, room) + + if len(events): + print(f'Found {len(events)} events') + await self.send_events(bot, events, room) async def send_events(self, bot, events, room): for event in events: @@ -137,15 +138,15 @@ class MatrixModule: def list_today(self, calid): startTime = datetime.datetime.utcnow() - startTime = startTime - datetime.timedelta(hours=startTime.hour, minutes=startTime.minute) + startTime = startTime.replace(hour = 0, minute = 0, second = 0, microsecond=0) endTime = startTime + datetime.timedelta(hours=24) now = startTime.isoformat() + 'Z' end = endTime.isoformat() + 'Z' + print('Looking for events between', now, end) events_result = self.service.events().list(calendarId=calid, timeMin=now, timeMax=end, maxResults=10, singleEvents=True, orderBy='startTime').execute() - events = events_result.get('items', []) - return events + return events_result.get('items', []) def help(self): return('Google calendar. Lists 10 next events by default. today = list today\'s events.')