-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
30 lines (26 loc) · 1.03 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
from mycroft import MycroftSkill, intent_file_handler, util as mutil
from pint import UnitRegistry
class UnitConverter(MycroftSkill):
def __init__(self):
MycroftSkill.__init__(self)
self.units = UnitRegistry()
self.Q_ = self.units.Quantity
@intent_file_handler('converter.unit.intent')
def handle_converter_unit(self, message):
try:
d = message.data
(firstu, secondu, seconda) = (d['firstunit'], d['secondunit'], d['secondamount'])
seconda = '1' if seconda == "a" else seconda
qfrom = self.Q_(seconda + " * " + secondu);
qTo = qfrom.to(firstu)
resDict = {
'firstAmount': mutil.nice_number(qTo.magnitude),
'firstUnit': firstu,
'secondAmount': seconda,
'secondUnit': secondu
}
self.speak_dialog('converter.unit', resDict)
except:
self.speak_dialog('converter.unit.failed')
def create_skill():
return UnitConverter()