-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
197 lines (151 loc) · 6.43 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# 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/>.
# Mycroft_my_family_tree
# Mycroft libraries
from adapt.intent import IntentBuilder
from mycroft.skills.core import MycroftSkill
from mycroft.util.log import getLogger
from mycroft import intent_handler
from os.path import dirname, exists, join
import requests
import os
import json
__author__ = 'henridbr' # hd@uip
LOGGER = getLogger(__name__)
class MyFamilyTreeSkill(MycroftSkill):
def __init__(self):
super(MyFamilyTreeSkill, self).__init__(name="MyFamilyTreeSkill")
@intent_handler(IntentBuilder("MyFamilyTreeIntent").require("MyFamilyTreeKeyword"))
def handle_family_learning_intent(self, message):
self.speak_dialog("got.it.memory")
### Find who is my ?
@intent_handler(IntentBuilder("FamilyMemberIntent").require("FamilyMemberKeyword"))
def handle_family_member_intent(self, message):
family_rank = message.data.get("FamilyMemberKeyword")
# print(family_rank)
with open(join(os.path.dirname(__file__), 'familybook.json'), "r") as read_file:
family = json.load(read_file)
membersname = family['family_dictionary']['members']
namelist = []
namegroup = ""
i=0
while i< len(membersname):
if (membersname[i]['rank'] == family_rank):
namelist.append(membersname[i]['first_name'])
i = i+1
i=1
if len(namelist) ==0 :
self.speak_dialog('you have no {}'.format(family_rank))
elif len(namelist) ==1 :
self.speak_dialog('{} is your {}'.format(namelist[0],family_rank))
else:
namegroup = namelist[0]
while i< len(namelist):
namegroup = namegroup +" and " + namelist[i]
i = i+1
self.speak_dialog('{} are your {}'.format(namegroup,family_rank))
#### Find Living Place of someone
@intent_handler(IntentBuilder("LivingPlaceIntent").require("LivingPlaceKeyword").require("FamilyFirstName"))
def handle_living_place(self, message):
member = message.data.get('FamilyFirstName')
with open(join(os.path.dirname(__file__), 'familybook.json'), "r") as read_file:
family = json.load(read_file)
membersname = family['family_dictionary']['members']
memberslivingplace ={}
i=0
foundit = ""
while i< len(membersname):
if (member.find(membersname[i]['first_name'].lower())>=0):
member = membersname[i]['first_name']
foundit = "found"
i=i+1
if (foundit==""):
self.speak('Sorry, I missed something')
else:
print(member)
i=0
while i< len(membersname):
who = membersname[i]['first_name']
where = membersname[i]['location']
memberslivingplace[who] = where
i=i+1
livingplace = memberslivingplace[member]
self.speak('{} is from {}'.format(member, livingplace))
#### Find Age of someone
@intent_handler(IntentBuilder("SomeOneAgeIntent").require("SomeOneAgeKeyword").require("FamilyFirstName"))
def handle_someone_age(self, message):
member = message.data.get('FamilyFirstName')
with open(join(os.path.dirname(__file__), 'familybook.json'), "r") as read_file:
family = json.load(read_file)
membersname = family['family_dictionary']['members']
membersage ={}
foundit = ""
i=0
while i< len(membersname):
if (member.find(membersname[i]['first_name'].lower())>=0):
member = membersname[i]['first_name']
foundit = "found"
i=i+1
if (foundit==""):
self.speak('Sorry, I missed something')
else:
print(member)
i=0
while i< len(membersname):
who = membersname[i]['first_name']
so_age = membersname[i]['age']
membersage[who] = so_age
i=i+1
member_age = membersage[member]
if (member_age == "dead"):
self.speak('{} is {}'.format(member, member_age))
else:
self.speak('{} is {} old'.format(member, member_age))
#### Find feature of someone
@intent_handler(IntentBuilder("SomeOneFeatureIntent").require("SomeOneFeatureKeyword").require("FamilyFirstName"))
def handle_someone_feature(self, message):
member = message.data.get('FamilyFirstName')
with open(join(os.path.dirname(__file__), 'familybook.json'), "r") as read_file:
family = json.load(read_file)
membersname = family['family_dictionary']['members']
membersfeature ={}
foundit = ""
i=0
while i< len(membersname):
if (member.find(membersname[i]['first_name'].lower())>=0):
member = membersname[i]['first_name']
foundit = "found"
i=i+1
if (foundit==""):
self.speak('Sorry, I missed something')
else:
print(member)
i=0
while i< len(membersname):
who = membersname[i]['first_name']
so_feature = membersname[i]['feature']
membersfeature[who] = so_feature
i=i+1
member_feature = membersfeature[member]
if (member_feature == ""):
self.speak('Sorry, I don\'t know more on {}'.format(member))
else:
self.speak('{} is really {}'.format(member, member_feature))
def stop(self):
pass
def create_skill():
return MyFamilyTreeSkill()