| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import logging
- 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')
- lines, terminator = ears.listen_until_terminated(timeout=_LISTEN_TIMEOUT, preferred_phrases=_GROCERIES)
- if terminator == 'cancel':
- tts.tts('cancelled')
- return
- else:
- items = []
- for line in lines:
- items.extend([t.strip() for t in line.split(' and ') if t.strip()])
- logging.info(items)
- tts.tts('ok')
- def call(self, trigger=None, **_):
- if trigger == 'food':
- self._groceries()
- else:
- tts.tts('Bad trigger')
- """
|