From dd738bc95cb6911a497be093117785a3f8f53a23 Mon Sep 17 00:00:00 2001 From: Pedro de Oliveira Date: Mon, 10 Feb 2020 22:57:47 +0000 Subject: [PATCH] Add wotd cron. Needs to be repeated every 60 seconds with Scheduler --- Priberam/plugin.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Priberam/plugin.py b/Priberam/plugin.py index 9b7ef3c..dab383d 100644 --- a/Priberam/plugin.py +++ b/Priberam/plugin.py @@ -38,6 +38,7 @@ except ImportError: # without the i18n module _ = lambda x: x import urllib.parse +from datetime import datetime import re import requests import atoma @@ -125,11 +126,17 @@ class Priberam(callbacks.Plugin): irc.reply(message, prefixNick=False) find = wrap(find, ['anything', optional('int', default=1)]) - def wotd(self, irc, msg, args): - """takes no arguments - + def wotd(self, irc, msg, args, argument): + """[argument] Returns the definition of the word of the day. + If [argument] is "cron" then just return if the time is 00:00. """ + + if argument == 'cron': + now = datetime.now() + if now.hour != 0 or now.minute != 0: + return + response = requests.get( "https://dicionario.priberam.org/DoDiaRSS.aspx", headers={'User-agent': 'Mozilla/5.0'} @@ -141,8 +148,7 @@ class Priberam(callbacks.Plugin): feed.items[0].title, definition['extra'], definition['value']), prefixNick=False) - wotd = wrap(wotd) - + wotd = wrap(wotd, [optional('anything')]) Class = Priberam