Ejemplo n.º 1
0
  def get_all(cls, user_id, date=None):
    """See base class."""
    if date is None:
      time_min = dateutils.today_midnight()
    else:
      time_min = dateutils.as_utc(
          date.replace(hour=0, minute=0, second=0, microsecond=0)
      )
    time_max = time_min + datetime.timedelta(days=1)
    credential = get_google_credential(user_id)
    http = httplib2.Http()
    http = credential.authorize(http)
    service = discovery.build("calendar", "v3", http=http)
    entries = []
    page_token = None

    while True:
      calendar_list = service.events().list(
          calendarId='primary',
          timeMin=time_min.isoformat(),
          timeMax=time_max.isoformat(),
          pageToken=page_token
      ).execute()
      entries.extend(calendar_list['items'])
      page_token = calendar_list.get('nextPageToken')
      if not page_token:
        break

    objects = [cls.create_object_from_entry(entry) for entry in entries]
    return objects
Ejemplo n.º 2
0
  def get_all(cls, user_id, date=None):
    """See base class."""
    if date is None:
      dt = dateutils.today_midnight()
    else:
      dt = dateutils.as_utc(
          date.replace(hour=0, minute=0, second=0, microsecond=0)
      )

    credential = get_rescuetime_credential(user_id)

    base_url = "https://www.rescuetime.com/anapi/data?key=%s" %(credential.token,)
    fields = "&perspective=interval"
    fields += "&resolution_time=minute"
    fields += "&restrict_begin=" + dt.strftime("%Y-%m-%d")
    fields += "&restrict_end=" + dt.strftime("%Y-%m-%d")
    fields += "&restrict_kind=activity"
    fields += "&restrict_kind=document"
    fields += "&format=json"

    request_url = base_url + fields
    api_response = urllib2.urlopen(urllib2.Request(request_url))
    d = json.loads(api_response.read())

    assert (d['row_headers'] == [u'Date', u'Time Spent (seconds)',
                                u'Number of People', u'Activity',
                                u'Document', u'Category', u'Productivity'])
    entries = d['rows']
    objects = [cls.create_object_from_entry(entry) for entry in entries]
    return objects
Ejemplo n.º 3
0
  def get_all(cls, user_id, date=None):
    """See base class."""
    credential = get_google_credential(user_id)
    http = httplib2.Http()
    http = credential.authorize(http)
    service = discovery.build("gmail", "v1", http=http)
    entries = []
    page_token = None

    if date is None:
      time_min = dateutils.today_midnight()
    else:
      time_min = dateutils.as_utc(
          date.replace(hour=0, minute=0, second=0, microsecond=0)
      )
    time_max = time_min + datetime.timedelta(days=1)

    query_string = 'after:{0} before:{1}'.format(
        time_min.strftime('%Y/%m/%d'),
        time_max.strftime('%Y/%m/%d')
    )

    while True:
      email_list = service.users().messages().list(
          q=query_string,
          userId='me',
          pageToken=page_token
      ).execute()
      for ids in email_list['messages']:
        msg = service.users().messages().get(userId='me',
                                             id=ids['id']).execute()
        entries.append(msg)
      page_token = email_list.get('nextPageToken')
      if not page_token:
        break

    objects = [cls.create_object_from_entry(entry) for entry in entries]
    return objects