-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
84 lines (67 loc) · 3.34 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Copyright 2016 Mycroft AI, Inc.
#
# This file is part of Mycroft Core.
#
# Mycroft Core is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Mycroft Core is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mycroft Core. If not, see <http://www.gnu.org/licenses/>.
# Visit https://docs.mycroft.ai/skill.creation for more detailed information
# on the structure of this skill and its containing folder, as well as
# instructions for designing your own skill based on this template.
# Import statements: the list of outside modules you'll be using in your
# skills, whether from other files in mycroft-core or from external libraries
from os.path import dirname
from adapt.intent import IntentBuilder
from mycroft.skills.core import MycroftSkill
from mycroft.util.log import getLogger
import requests
__author__ = 'Steven'
# Logger: used for debug lines, like "LOGGER.debug(xyz)". These
# statements will show up in the command line when running Mycroft.
LOGGER = getLogger(__name__)
# The logic of each skill is contained within its own class, which inherits
# base methods from the MycroftSkill class with the syntax you can see below:
# "class ____Skill(MycroftSkill)"
class HistoryDeathSkill(MycroftSkill):
# The constructor of the skill, which calls MycroftSkill's constructor
def __init__(self):
super(HistoryDeathSkill, self).__init__(name="HistoryDeathSkill")
# This method loads the files needed for the skill's functioning, and
# creates and registers each intent that the skill uses
def initialize(self):
self.load_data_files(dirname(__file__))
random_event_intent = IntentBuilder("RandomEventIntent").\
require("RandomEventKeyword").build()
self.register_intent(random_event_intent, self.handle_random_event_intent)
# The "handle_xxxx_intent" functions define Mycroft's behavior when
# each of the skill's intents is triggered: in this case, he simply
# speaks a response. Note that the "speak_dialog" method doesn't
# actually speak the text it's passed--instead, that text is the filename
# of a file in the dialog folder, and Mycroft speaks its contents when
# the method is called.
def handle_random_event_intent(self, message):
apiurl = 'http://history.muffinlabs.com/date'
req = requests.get(apiurl)
json_output = req.json()
output = json_output['data']
deathhistory = output['Deaths']
self.speak("Today in history {} died".format(deathhistory[0]['text']))
# The "stop" method defines what Mycroft does when told to stop during
# the skill's execution. In this case, since the skill's functionality
# is extremely simple, the method just contains the keyword "pass", which
# does nothing.
def stop(self):
pass
# The "create_skill()" method is used to create an instance of the skill.
# Note that it's outside the class itself.
def create_skill():
return HistoryDeathSkill()