journee_mondiale: ditch the site for a static list
This commit is contained in:
parent
7a2e011272
commit
edbc35aa19
|
@ -77,8 +77,9 @@
|
||||||
"deny_message": "No."
|
"deny_message": "No."
|
||||||
},
|
},
|
||||||
"journeemondiale": {
|
"journeemondiale": {
|
||||||
"commands": ["journée mondiale"],
|
"commands": ["international day"],
|
||||||
"url": "https://www.journee-mondiale.com/"
|
"dates": ["01-01 NYE"],
|
||||||
|
"no_entry_reply": "Nothing special today."
|
||||||
},
|
},
|
||||||
"meteofrance": {
|
"meteofrance": {
|
||||||
"commands": ["météo"],
|
"commands": ["météo"],
|
||||||
|
|
|
@ -1,17 +1,26 @@
|
||||||
try:
|
import datetime
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
DEPENDENCIES_FOUND = True
|
|
||||||
except ImportError:
|
|
||||||
DEPENDENCIES_FOUND = False
|
|
||||||
|
|
||||||
from edmond.plugin import Plugin
|
from edmond.plugin import Plugin
|
||||||
from edmond.utils import http_get
|
|
||||||
|
|
||||||
|
|
||||||
class JourneeMondialePlugin(Plugin):
|
class JourneeMondialePlugin(Plugin):
|
||||||
"""This plugin gets today's international observance (french)."""
|
"""This plugin shows today's international observance.
|
||||||
|
|
||||||
REQUIRED_CONFIGS = ["commands", "url"]
|
It used to fetch data from the website journee-mondiale.com but it is
|
||||||
|
regularly broken so it is now loading a static list as a resource. This
|
||||||
|
list uses the format "MM-DD Name", one per line, e.g.:
|
||||||
|
|
||||||
|
```
|
||||||
|
01-01 NYE
|
||||||
|
08-03 Something the 3rd of August
|
||||||
|
12-25 Christmas
|
||||||
|
```
|
||||||
|
|
||||||
|
A list can be found on the UN website but it has to be converted by hand:
|
||||||
|
https://www.un.org/en/observances/list-days-weeks
|
||||||
|
"""
|
||||||
|
|
||||||
|
REQUIRED_CONFIGS = ["commands", "dates", "no_entry_reply"]
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
super().__init__(bot)
|
super().__init__(bot)
|
||||||
|
@ -20,20 +29,17 @@ class JourneeMondialePlugin(Plugin):
|
||||||
if not self.should_handle_command(event.arguments[0], no_content=True):
|
if not self.should_handle_command(event.arguments[0], no_content=True):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
response = http_get(self.config["url"])
|
now = datetime.datetime.now()
|
||||||
if not response:
|
date_tag = f"{now.month:02}-{now.day:02}"
|
||||||
self.signal_failure(event.target)
|
today_obs = map(
|
||||||
return True
|
lambda line: line.split(maxsplit=1)[1],
|
||||||
|
filter(
|
||||||
soup = BeautifulSoup(response, "html.parser")
|
lambda line: line.startswith(date_tag),
|
||||||
try:
|
self.config["dates"]
|
||||||
jm = soup.find("div", id="journeesDuJour").find("h2").string
|
)
|
||||||
except (ValueError, KeyError):
|
)
|
||||||
self.signal_failure(event.target)
|
reply = ", ".join(today_obs)
|
||||||
return True
|
if not reply:
|
||||||
|
reply = self.config["no_entry_reply"]
|
||||||
if jm:
|
self.bot.say(event.target, reply)
|
||||||
self.bot.say(event.target, jm)
|
|
||||||
else:
|
|
||||||
self.signal_failure(event.target)
|
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in a new issue