Edm0nd/edmond/plugins/journee_mondiale.py

34 lines
966 B
Python
Raw Normal View History

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
response = http_get(self.config["url"])
if not response:
self.signal_failure()
return True
soup = BeautifulSoup(response, "html.parser")
try:
jm = soup.find("div", id="journeesDuJour").find("h2").string
except (ValueError, KeyError):
self.signal_failure()
return True
self.bot.say(event.target, jm)
return True