-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
66 lines (50 loc) · 2.39 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
# TODO: Add an appropriate license to your skill before publishing. See
# the LICENSE file for more information.
# Below is the list of outside modules you'll be using in your skill.
# They might be built-in to Python, from mycroft-core or from external
# libraries. If you use an external library, be sure to include it
# in the requirements.txt file so the library is installed properly
# when the skill gets installed later by a user.
from adapt.intent import IntentBuilder
#from mycroft.skills.core import MycroftSkill, intent_handler
from mycroft import MycroftSkill, intent_file_handler, intent_handler, AdaptIntent
from mycroft.util.log import LOG
import requests
API_URL = 'http://universities.hipolabs.com/'
SEARCH = API_URL + 'search'
def search_university(state_name):
parameters = {"name": state_name, "country": 'united states'}
r = requests.get(SEARCH, params=parameters)
if (200 <= r.status_code < 300):
data = r.json()
university_names = [li['name'] for li in data]
university_names = list(set(university_names))
return university_names
else:
return None
# TODO: Change "Template" to a unique name for your skill
class StateUniversitySkill(MycroftSkill):
# The constructor of the skill, which calls MycroftSkill's constructor
def __init__(self):
super(StateUniversitySkill, self).__init__(name="StateUniversitySkill")
@intent_file_handler('State.intent')
def get_state_university(self, message):
list_university = search_university(message.data['state'])
#list_university = True
if list_university:
#self.speak_dialog("SateUniversity", {'state': 'oklahoma', 'university': list_university})
self.speak_dialog("SateUniversity", {'state': message.data['state'], 'university': list_university})
else:
self.speak_dialog('NotFound')
# 'Greetings planet earth'
@intent_handler(IntentBuilder("").require("State").require("University"))
def handle_state_university_intent(self, message):
# Mycroft will randomly speak one of the lines from the file
# dialogs/en-us/hello.world.dialog
self.speak_dialog("state.university")
# def stop(self):
# return False
# 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 StateUniversitySkill()