2020-10-09 22:32:36 +02:00
|
|
|
try:
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
DEPENDENCIES_FOUND = True
|
|
|
|
except ImportError:
|
|
|
|
DEPENDENCIES_FOUND = False
|
|
|
|
|
|
|
|
from edmond.plugin import Plugin
|
|
|
|
from edmond.utils import http_get
|
|
|
|
|
|
|
|
|
|
|
|
class JourneeMondialePlugin(Plugin):
|
|
|
|
"""This plugin gets today's international observance (french)."""
|
|
|
|
|
|
|
|
REQUIRED_CONFIGS = ["commands", "url"]
|
|
|
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
super().__init__(bot)
|
|
|
|
|
|
|
|
def on_pubmsg(self, event):
|
|
|
|
if not self.should_handle_command(event.arguments[0], no_content=True):
|
|
|
|
return False
|
2021-12-02 11:36:30 +01:00
|
|
|
|
2020-10-09 22:32:36 +02:00
|
|
|
response = http_get(self.config["url"])
|
|
|
|
if not response:
|
2020-10-09 22:34:47 +02:00
|
|
|
self.signal_failure(event.target)
|
2020-10-09 22:32:36 +02:00
|
|
|
return True
|
2021-12-02 11:36:30 +01:00
|
|
|
|
2020-10-09 22:32:36 +02:00
|
|
|
soup = BeautifulSoup(response, "html.parser")
|
|
|
|
try:
|
|
|
|
jm = soup.find("div", id="journeesDuJour").find("h2").string
|
|
|
|
except (ValueError, KeyError):
|
2020-10-09 22:34:47 +02:00
|
|
|
self.signal_failure(event.target)
|
2020-10-09 22:32:36 +02:00
|
|
|
return True
|
2021-12-02 11:36:30 +01:00
|
|
|
|
2021-11-23 14:14:30 +01:00
|
|
|
if jm:
|
|
|
|
self.bot.say(event.target, jm)
|
2021-12-02 11:36:30 +01:00
|
|
|
else:
|
|
|
|
self.signal_failure(event.target)
|
2020-10-09 22:32:36 +02:00
|
|
|
return True
|