From 70f7a9809292f30faf1c5c60d086bf4ce2045e00 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sat, 12 Jun 2021 15:08:17 +0200 Subject: [PATCH] update python-telegram-bot API --- README.md | 14 ++++++++++++++ telegram-bot/Dockerfile | 2 +- telegram-bot/telegram-onthisday.py | 17 +++++++++-------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 5d6c0f2..71f0dbf 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,17 @@ Requires https://github.com/jsvine/markovify 2019 - Storms provoke severe flooding on the Catalaunian Plains, Attila lays siege to the World Wide Web. ``` + +# License + +Copyright 2019-2021 Davide Alberani + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/telegram-bot/Dockerfile b/telegram-bot/Dockerfile index e893531..f198172 100644 --- a/telegram-bot/Dockerfile +++ b/telegram-bot/Dockerfile @@ -3,7 +3,7 @@ LABEL \ maintainer="Davide Alberani " RUN \ - apk add --no-cache git python3 py3-cffi py3-six py3-requests py3-cryptography && \ + apk add --no-cache git python3 py3-cffi py3-six py3-requests py3-cryptography py3-pip && \ pip3 install python-telegram-bot && \ pip3 install markovify && \ cd / && \ diff --git a/telegram-bot/telegram-onthisday.py b/telegram-bot/telegram-onthisday.py index 9fe0583..78ecf88 100755 --- a/telegram-bot/telegram-onthisday.py +++ b/telegram-bot/telegram-onthisday.py @@ -4,7 +4,7 @@ Build it with: docker build -t telegram-onthisday . Run it with something like: docker run -ti --rm -e EVENTS_TOKEN=your-telegram-token telegram-onthisday -Copyright 2019 Davide Alberani Apache 2.0 license +Copyright 2019-2021 Davide Alberani Apache 2.0 license """ import os @@ -45,18 +45,19 @@ def getEvents(day=None): return stdout -def events(bot, update, args=None): +def events(bot, update): day = None - if args and args[0]: - day = args[0].strip() + txts = bot.message.text.split() + if len(txts) == 2: + day = txts[1] events = getEvents(day) - logging.info('%s wants some news; serving:\n%s' % (update.message.from_user.name, events)) - update.message.reply_text(events) + logging.info('%s wants some news; serving:\n%s' % (bot.effective_user.username, events)) + bot.message.reply_text(events) def about(bot, update): - logging.info('%s required more info' % update.message.from_user.name) - update.message.reply_text('See https://github.com/alberanid/onthisday\n\n/today to use the current date\n\n/date 07/30 for July 30') + logging.info('%s required more info' % bot.effective_user.username) + bot.message.reply_text('See https://github.com/alberanid/onthisday\n\n/today to use the current date\n\n/date 07/30 for July 30') if __name__ == '__main__':