forked from adropofilm/word-of-the-day-skill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
37 lines (24 loc) · 1.1 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from bs4 import BeautifulSoup
import requests
from ovos_workshop.decorators import intent_handler
from ovos_workshop.skills.auto_translatable import UniversalSkill
from ovos_workshop.intents import IntentBuilder
__author__ = 'fmohamed'
def get_wod():
html = requests.get("https://www.dictionary.com/e/word-of-the-day").text
soup = BeautifulSoup(html, "html.parser")
h = soup.find("div", {"class": "otd-item-headword__word"})
wod = h.text.strip()
h = soup.find("div", {"class": "otd-item-headword__pos-blocks"})
definition = h.text.strip().split("\n")[-1]
return wod, definition
class WordOfTheDaySkill(UniversalSkill):
def __init__(self, *args, **kwargs):
# website is english only, apply bidirectional translation
super().__init__(internal_language="en-us", *args, **kwargs)
@intent_handler(IntentBuilder("WordOfTheDayIntent").require("WordOfTheDayKeyword"))
def handle_word_of_the_day_intent(self, message):
self.speak_dialog("word.of.day")
wod, definition = get_wod()
self.speak(f"The word of the day is {wod}")
self.speak(definition)