-
Notifications
You must be signed in to change notification settings - Fork 3
/
tasker_autoremote.py
46 lines (34 loc) · 1.46 KB
/
tasker_autoremote.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
import logging
import requests
from kalliope.core.NeuronModule import NeuronModule, MissingParameterException
logging.basicConfig()
logger = logging.getLogger("kalliope")
class Tasker_autoremote(NeuronModule):
def __init__(self, **kwargs):
super(Tasker_autoremote, self).__init__(**kwargs)
# check if parameters have been provided
self.key = kwargs.get('key', None)
self.message = kwargs.get('message', None)
self.password = kwargs.get('password', None)
if self._is_parameters_ok():
# create the payload
data = {'key': self.key,
'message': self.message}
# Add password to data if set
if self.password != None:
data.update({ 'password': self.password})
url = "https://autoremotejoaomgcd.appspot.com/sendmessage"
# post
r = requests.post(url, data=data)
logging.debug("Post to tasker automore response: %s" % r.status_code)
def _is_parameters_ok(self):
"""
Check if received parameters are ok to perform operations in the neuron
:return: true if parameters are ok, raise an exception otherwise
.. raises:: MissingParameterException
"""
if self.key is None:
raise MissingParameterException("key parameter required")
if self.message is None:
raise MissingParameterException("message parameter required")
return True