Created
February 26, 2020 19:18
-
-
Save rennerocha/6eea3324d1abbfa9aa12dcdf662fa391 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ics import Calendar | |
from telegram.ext import Updater, CommandHandler | |
def ics_calendar(): | |
with open("lhc.ics", "r") as f: | |
calendar = Calendar(f.read()) | |
return calendar | |
def quando(update, context): | |
calendar = ics_calendar() | |
next_event = min(list(calendar.events), key=lambda e: e.begin) | |
event = { | |
"title": next_event.name, | |
"date": next_event.begin.strftime("%d/%m/%Y"), | |
"url": next_event.url, | |
} | |
next_event_msg = f"Vai rolar \"{event['title']}\" em {event['date']}. Mais informações em {event['url']}." | |
update.message.reply_text(next_event_msg) | |
API_TOKEN = "<TOKEN>" | |
updater = Updater(API_TOKEN, use_context=True) | |
updater.dispatcher.add_handler(CommandHandler("quando", quando)) | |
updater.start_polling() | |
updater.idle() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment