コード例 #1
0
ファイル: main_handler.py プロジェクト: jbyeung/glassgtasks
  def _select_tasklist(self):
    # selects tasklist, assigns to TASKLIST_NAME
    userid, creds = util.load_session_credentials(self)
    tasks_service = util.create_service('tasks', 'v1', creds)

    tasklist_id = self.request.get('select')
    logging.info("select")
    logging.info(self.request.get('select'))

    if tasklist_id == '':
      return "Please select a tasklist before trying to add it."
    else:
      #set name/id to db
      my_tasklist = TasklistStore(owner=self.userid)
      my_tasklist.my_id = tasklist_id
      #TASKLIST_NAMES.append(tasklist_title)

      tasklists = tasks_service.tasklists().list().execute()
      for tasklist in tasklists['items']:
        if tasklist_id == tasklist['id']:
          my_tasklist.my_name = tasklist['title']
            #TASKLIST_IDS[tasklist_title] = tasklist['id']

      my_tasklist.put()

      return my_tasklist.my_name + " selected successfully"
コード例 #2
0
ファイル: handler.py プロジェクト: jbyeung/glassgtasks
  def _handle_timeline_notification(self, data):
    """Handle timeline notification."""
    #userid, creds = util.load_session_credentials(self)
    item_id = data.get('itemId')
    userid = data.get('userToken')

    #process actions
    logging.info(userid)
    #for user_action in data.get('userActions', []):
    if data.get('userActions', [])[0]:
        user_action = data.get('userActions', [])[0]
        logging.info(user_action)
        payload = user_action.get('payload')

        if user_action.get('type') == 'REPLY':
            # handle adding a new task via voice input
            # create local vars for selected tasklist
            
            transcription_item = self.mirror_service.timeline().get(id=item_id).execute()
            transcription = transcription_item.get('text')

            timeline_item_id = transcription_item.get('inReplyTo')
            item = self.mirror_service.timeline().get(id=timeline_item_id).execute()
            tasklist_id = item.get('title')     #this is actually the tasklist id stashed in _new_tasklist from main_handler
            logging.info(tasklist_id)
            logging.info("tasklist id above")
            
            q = TasklistStore.all()
            q.filter("owner = ",userid)
            q.filter("my_id = ",tasklist_id)
            q.run()
            for p in q:
                tasklist_name = p.my_name
            

            if transcription:   #don't do anything if its empty
                task = {
                    'title':transcription
                }
                logging.info('transcribed this text: ')
                logging.info(transcription)
                
                try:
                    self.mirror_service.timeline().delete(id=item_id).execute()
                    logging.info('deleted the voice item')
                except errors.HttpError, e:
                    logging.info('An error occurred: %s' % error)

                try:
                    result = self.tasks_service.tasks().insert(tasklist=tasklist_id, body=task).execute()
                    logging.info('new task is inserted now')
                except errors.HttpError, error:
                    logging.info('An error occured: %s' % error)

            item_id = timeline_item_id
コード例 #3
0
ファイル: handler.py プロジェクト: jbyeung/glassgtasks
  def post(self):
    """Delete the user's credentials from the datastore."""
    urlfetch.fetch(OAUTH2_REVOKE_ENDPOINT % self.credentials.refresh_token)
    util.store_userid(self, '')

    #clear datastore object for tasklists
    q = TasklistStore.all()
    q.filter("owner = ",self.userid)

    for p in q.run():
      p.delete()

    credentials_entity = Credentials.get_by_key_name(self.userid)
    if credentials_entity:
      credentials_entity.delete()
      
    self.redirect('/')
コード例 #4
0
ファイル: main_handler.py プロジェクト: jbyeung/glassgtasks
  def _render_template(self, message=None):
    """Render the main page template."""

    userid, creds = util.load_session_credentials(self)
    tasks_service = util.create_service('tasks', 'v1', creds)

    template_values = {'userId': self.userid}

    if message:
      template_values['message'] = message
    
    # self.mirror_service is initialized in util.auth_required
    subscriptions = self.mirror_service.subscriptions().list().execute()
    for subscription in subscriptions.get('items', []):
      collection = subscription.get('collection')
      if collection == 'timeline':
        template_values['timelineSubscriptionExists'] = True
    
    # pull from tasks api, list of tasklists
    tasklists = tasks_service.tasklists().list().execute()
    template_values['tasklists'] = tasklists['items']

    #load the tasklist names and ids from db if exists
    #q = db.GqlQuery("SELECT * FROM TasklistStore " + 
    #                "WHERE owner = " + userid)
    q = TasklistStore.all()
    q.filter("owner = ",self.userid)
    TASKLIST_NAMES = []
    for p in q.run():
      TASKLIST_NAMES.append(p.my_name)
    if TASKLIST_NAMES == []:
      TASKLIST_NAMES.append("None")

    template_values['synced'] = TASKLIST_NAMES

    template = jinja_environment.get_template('templates/index.html')
    self.response.out.write(template.render(template_values))
コード例 #5
0
ファイル: main_handler.py プロジェクト: jbyeung/glassgtasks
  def _new_tasklist(self):
    userid, creds = util.load_session_credentials(self)
    tasks_service = util.create_service('tasks', 'v1', creds)
    mirror_service = util.create_service('mirror', 'v1', creds)

    logging.info('Inserting timeline items')
    # Note that icons will not show up when making counters on a
    # locally hosted web interface.
    #mirror_service = util.create_service('mirror', 'v1', creds)
    #tasks_service = util.create_service('tasks', 'v1', creds)


    ############################  TASKS API STUFF #######
    # create empty task list @glass if none selected or none exist
    #q = db.GqlQuery("SELECT * FROM TasklistStore " + 
    #                "WHERE owner = " + userid)
    q = TasklistStore.all()
    q.filter("owner = ",self.userid)
    q.run()
    #if no tasklists, insert a default one
    if q:
        logging.info('not inserting')
    else:
        logging.info('no tasklist selected, inserting @glass ')
        tasklist = {
          'title': '@glass'
        }
        result = tasks_service.tasklists().insert(body=tasklist).execute()
        my_tasklist = TasklistStore(owner = userid, my_name = tasklist_title,
                                    my_id = result['id'])
        my_tasklist.put()
        
    ## now for each selected tasklist, post tasks to timeline
    for p in q:
      tasklist_id = p.my_id
      tasklist_name = p.my_name

      # insert seed tasks
      task = {
        'title': 'Glass interface synced to this list!',
        'notes': 'Try adding a new task with the voice command!'
      }
      result = tasks_service.tasks().insert(tasklist=tasklist_id, body=task).execute()
      
      # grab all the tasks in tasklist to display
      result = tasks_service.tasks().list(tasklist=tasklist_id).execute()

      #filter out completed tasks
      tasks = []
      for i, task in enumerate(result['items']):
        if task['status'] != 'completed':
          tasks.append(task)

      #grabbing all tasks now instead of just 5
      #indx = 5 if len(tasks) > 4 else len(tasks)
      #tasks = tasks[0:indx]

      if len(tasks) == 0:
        tasks.append({'title': 'No tasks!'})
 
      #render html
      # new_fields = {
      #     'list_title': tasklist_name,
      #     'tasks': tasks
      # }
      body = {
          'notification': {'level': 'DEFAULT'},
          'title': tasklist_id,     #secret way of stashing the tasklist id in the timeline item
          'html': get_html_from_tasks(tasks_service, tasklist_id, tasklist_name),
          'menuItems': [
              {
                  'action': 'REPLY',
                  'id': 'create_task',
                  'values': [{
                      'displayName': 'New Task',
                      'iconUrl': util.get_full_url(self, '/static/images/new_task.png')}]
              },
              {
                  'action': 'CUSTOM',
                  'id': 'refresh',
                  'values': [{
                      'displayName': 'Refresh',
                      'iconUrl': util.get_full_url(self, '/static/images/refresh2.png')}]
              },
              {'action': 'TOGGLE_PINNED'},
              {'action': 'DELETE'}
          ]
      }
      # custom_item_fields.set_multiple(body, new_fields, TIMELINE_ITEM_TEMPLATE_URL)


      # self.mirror_service is initialized in util.auth_required.
      # add card to timeline
      try:
        result = self.mirror_service.timeline().insert(body=body).execute()
        if result:
          item_id = result['id']
          # logging.info('mainhandler about to defer')
          # deferred.defer(auto_refresh, creds, mirror_service, tasks_service, item_id, tasklist_name, tasklist_id, True)
          # logging.info('mainhandler deferred')

      except errors.HttpError, error:
        logging.info ('an error has occured %s ', error)