|
|
@@ -3,11 +3,53 @@ import base
|
|
|
import tts
|
|
|
import clips
|
|
|
import ears
|
|
|
+import requests
|
|
|
|
|
|
_LISTEN_TIMEOUT = 600
|
|
|
_GROCERIES = ['milk', 'bread']
|
|
|
|
|
|
+_WUNDERLIST_CLIENT_ID = '34e0e31945afeb63e1b8'
|
|
|
+_WUNDERLIST_ACCESS_TOKEN = 'a7258e8b6596fdaffc904fc6b65d40c23afe6d2a28bfe7be1a9026d44b59'
|
|
|
+
|
|
|
+class WunderlistClient(object):
|
|
|
+ lists = None
|
|
|
+
|
|
|
+ def __init__(self, client_id, access_token):
|
|
|
+ self.client_id = client_id
|
|
|
+ self.access_token = access_token
|
|
|
+
|
|
|
+ def call(self, method, url, body=None):
|
|
|
+ headers = {
|
|
|
+ 'x-client-id': self.client_id,
|
|
|
+ 'x-access-token': self.access_token,
|
|
|
+ 'content-type': 'application/json',
|
|
|
+ 'accept': 'application/json'
|
|
|
+ }
|
|
|
+
|
|
|
+ resp = requests.request(method, url, headers=headers, json=body)
|
|
|
+
|
|
|
+ if resp.status_code < 300:
|
|
|
+ return resp.json()
|
|
|
+ else:
|
|
|
+ raise Exception(resp.content)
|
|
|
+
|
|
|
+ def create_task(self, list_id, title):
|
|
|
+ self.call('POST', 'https://a.wunderlist.com/api/v1/tasks', {'list_id': list_id, 'title': title})
|
|
|
+
|
|
|
+ def init(self):
|
|
|
+ lists_res = self.call('GET', 'https://a.wunderlist.com/api/v1/lists')
|
|
|
+ self.lists = {x['title'].lower(): x['id'] for x in lists_res}
|
|
|
+
|
|
|
+c = WunderlistClient(_WUNDERLIST_CLIENT_ID, _WUNDERLIST_ACCESS_TOKEN)
|
|
|
+c.init()
|
|
|
+c.create_task(c.lists['food'], 'Test #1')
|
|
|
+
|
|
|
+"""
|
|
|
class WunderbarTodo(base.BaseFunction):
|
|
|
+ def init(self):
|
|
|
+ self.client = WunderlistClient(_WUNDERLIST_CLIENT_ID, _WUNDERLIST_ACCESS_TOKEN)
|
|
|
+ return self.client.init()
|
|
|
+
|
|
|
def _groceries(self):
|
|
|
tts.tts('ready')
|
|
|
|
|
|
@@ -33,3 +75,4 @@ class WunderbarTodo(base.BaseFunction):
|
|
|
else:
|
|
|
tts.tts('Bad trigger')
|
|
|
|
|
|
+"""
|