Compare commits
No commits in common. "7f2fa0817e5eb0234675abfd33dbe4752b5d7cde" and "65f9e8494af3d76cd4a27a281db9d1c48b47ae78" have entirely different histories.
7f2fa0817e
...
65f9e8494a
|
@ -1,24 +1,14 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
# BS is optional and only for scrapping journee-mondiale.com, thus why we do not
|
|
||||||
# mark the dependencies flag here.
|
|
||||||
try:
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
except ImportError:
|
|
||||||
BeautifulSoup = None
|
|
||||||
|
|
||||||
from edmond.plugin import Plugin
|
from edmond.plugin import Plugin
|
||||||
from edmond.utils import http_get
|
|
||||||
|
|
||||||
|
|
||||||
class JourneeMondialePlugin(Plugin):
|
class JourneeMondialePlugin(Plugin):
|
||||||
"""This plugin shows today's international observance.
|
"""This plugin shows today's international observance.
|
||||||
|
|
||||||
It used to fetch data from the website journee-mondiale.com but it is
|
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, and the
|
regularly broken so it is now loading a static list as a resource. This
|
||||||
website is fetched only if the user adds the "jmcom" config value to True.
|
list uses the format "MM-DD Name", one per line, e.g.:
|
||||||
|
|
||||||
The local list uses the format "MM-DD Name", one per line, e.g.:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
01-01 NYE
|
01-01 NYE
|
||||||
|
@ -39,22 +29,6 @@ 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
|
||||||
|
|
||||||
main_reply = self.get_registered_days()
|
|
||||||
if main_reply:
|
|
||||||
self.bot.say(event.target, main_reply)
|
|
||||||
|
|
||||||
jmcom_reply = ""
|
|
||||||
if self.config.get("jmcom", False) is True:
|
|
||||||
jmcom_reply = self.get_jmcom_days()
|
|
||||||
if jmcom_reply:
|
|
||||||
self.bot.say(event.target, jmcom_reply)
|
|
||||||
|
|
||||||
if not (main_reply or jmcom_reply):
|
|
||||||
self.bot.say(event.target, self.config["no_entry_reply"])
|
|
||||||
return True
|
|
||||||
|
|
||||||
def get_registered_days(self) -> str:
|
|
||||||
"""Get international days for the local list."""
|
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
date_tag = f"{now.month:02}-{now.day:02}"
|
date_tag = f"{now.month:02}-{now.day:02}"
|
||||||
today_obs = map(
|
today_obs = map(
|
||||||
|
@ -63,27 +37,8 @@ class JourneeMondialePlugin(Plugin):
|
||||||
lambda line: line.startswith(date_tag), self.config["dates"]
|
lambda line: line.startswith(date_tag), self.config["dates"]
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
days = ", ".join(today_obs)
|
reply = ", ".join(today_obs)
|
||||||
return reply
|
if not reply:
|
||||||
|
reply = self.config["no_entry_reply"]
|
||||||
def get_jmcom_days(self) -> str:
|
self.bot.say(event.target, reply)
|
||||||
"""Get international days from journee-mondiale.com."""
|
return True
|
||||||
response = http_get(self.config["url"])
|
|
||||||
if not response:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
soup = BeautifulSoup(response, "html.parser")
|
|
||||||
entries = []
|
|
||||||
try:
|
|
||||||
items = soup.find("div", id="journeesDuJour").find_all("article")
|
|
||||||
for item in items:
|
|
||||||
entries.append({
|
|
||||||
"url": item.find("a").href,
|
|
||||||
"title": item.find("h2").string,
|
|
||||||
})
|
|
||||||
except (ValueError, KeyError):
|
|
||||||
return ""
|
|
||||||
|
|
||||||
# TODO add plus plugin support
|
|
||||||
|
|
||||||
return ", ".join(map(lambda i: i["title"], entries))
|
|
||||||
|
|
|
@ -73,12 +73,7 @@ class TaxrefPlugin(Plugin):
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
self.signal_failure(target)
|
self.signal_failure(target)
|
||||||
return
|
return
|
||||||
try:
|
|
||||||
data = response.json()
|
data = response.json()
|
||||||
except ValueError:
|
|
||||||
self.signal_failure(target)
|
|
||||||
return
|
|
||||||
|
|
||||||
items = data.get("_embedded", {}).get("taxa", [])
|
items = data.get("_embedded", {}).get("taxa", [])
|
||||||
|
|
||||||
if not items:
|
if not items:
|
||||||
|
@ -200,11 +195,7 @@ class TaxrefPlugin(Plugin):
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
self.signal_failure(target)
|
self.signal_failure(target)
|
||||||
return
|
return
|
||||||
try:
|
|
||||||
data = response.json()
|
data = response.json()
|
||||||
except ValueError:
|
|
||||||
self.signal_failure(target)
|
|
||||||
return
|
|
||||||
items = data.get("_embedded", {}).get("taxa", [])
|
items = data.get("_embedded", {}).get("taxa", [])
|
||||||
|
|
||||||
if not items:
|
if not items:
|
||||||
|
|
Loading…
Reference in a new issue