示例#1
0
def saveAccessToken(moves_access_info, our_uuid):
  moves_access_info["our_uuid"] = our_uuid
  moves_uid = moves_access_info["user_id"]
  moves_access_info["_id"] = moves_uid

  user_access_table = get_moves_db()
  if (user_access_table.find({"_id": moves_uid}).count() == 0):
    user_access_table.insert(moves_access_info)
  else:
    user_access_table.update({"_id": moves_uid}, moves_access_info)
示例#2
0
def saveAccessToken(moves_access_info, our_uuid):
    moves_access_info["our_uuid"] = our_uuid
    moves_uid = moves_access_info["user_id"]
    moves_access_info["_id"] = moves_uid

    user_access_table = get_moves_db()
    if (user_access_table.find({"_id": moves_uid}).count() == 0):
        user_access_table.insert(moves_access_info)
    else:
        user_access_table.update({"_id": moves_uid}, moves_access_info)
示例#3
0
def collect():
    key_file = open('keys.json')
    key_data = json.load(key_file)

    m = Moves(client_id=key_data["client_id"],
              client_secret=key_data["client_secret"],
              redirect_url=key_data["redirect_url"])

    for (i, user) in enumerate(get_moves_db().find()):
        if i != 0 and i % 10 == 0:
            logging.info("Finished 10 users, sleeping for two minutes...")
            sleep(2 * 60)
        access_token = user['access_token']
        if access_token == "Ignore_me":
            logging.info("Found entry to ignore for user %s" % user)
            continue
        logging.info("%s: Getting data for user %s with token %s" %
                     (datetime.now(), user['our_uuid'], user['access_token']))
        user_uuid = user['our_uuid']
        # logging.debug(user_uuid)
        profile = m.get_profile(token=access_token)
        # logging.debug(profile)
        tzStr = getTimezone(profile)
        tz = pytz.timezone(tzStr)

        # So the documentation both here:
        # http://www.enricozini.org/2009/debian/using-python-datetime/
        # and here:
        # http://pytz.sourceforge.net/
        # says that we should use utcnow() because now() is not reliable.
        # unfortunately, using utcnow() on my desktop, where the timezone is set, causes the localized time to be wrong
        # now() works
        # testing with now() on the server as well
        # now() didn't work on the server either
        # in fact, pytz localize() (i.e. tz.localize(datetime.now()) seems broken
        # fortunately, astimezone() seems to work, so we are using it here

        dateFormat = "%Y-%m-%d"
        # endPoint = "user/storyline/daily/%s?trackPoints=true" % ('20140303')
        endPoint_today = "user/storyline/daily/%s?trackPoints=true" % (
            datetime.now(pytz.utc).astimezone(tz).strftime(dateFormat))
        endPoint_yesterday = "user/storyline/daily/%s?trackPoints=true" % (
            (datetime.now(pytz.utc).astimezone(tz) -
             timedelta(1)).strftime(dateFormat))
        result_today = m.get(token=access_token, endpoint=endPoint_today)
        result_yesterday = m.get(token=access_token,
                                 endpoint=endPoint_yesterday)
        logging.debug("result_today.type = %s, result_yesterday = %s" %
                      (type(result_today), type(result_yesterday)))
        # logging.debug(json.dumps(result_yesterday))

        # result=result_today+result_yesterday
        processResult(user_uuid, result_today)
        processResult(user_uuid, result_yesterday)
示例#4
0
def collect():
  key_file = open('keys.json')
  key_data = json.load(key_file)

  m = Moves(client_id = key_data["client_id"],
            client_secret = key_data["client_secret"],
            redirect_url = key_data["redirect_url"])

  for (i, user) in enumerate(get_moves_db().find()):
    if i != 0 and i % 10 == 0:
        logging.info("Finished 10 users, sleeping for two minutes...")
        sleep(2 * 60)
    access_token = user['access_token']
    if access_token == "Ignore_me":
      logging.info("Found entry to ignore for user %s" % user)
      continue
    logging.info("%s: Getting data for user %s with token %s" % (datetime.now(), user['our_uuid'], user['access_token']))
    user_uuid=user['our_uuid']
    # logging.debug(user_uuid)
    profile = m.get_profile(token = access_token)
    # logging.debug(profile)
    tzStr = getTimezone(profile)
    tz = pytz.timezone(tzStr)

    # So the documentation both here:
    # http://www.enricozini.org/2009/debian/using-python-datetime/
    # and here:
    # http://pytz.sourceforge.net/
    # says that we should use utcnow() because now() is not reliable.
    # unfortunately, using utcnow() on my desktop, where the timezone is set, causes the localized time to be wrong
    # now() works
    # testing with now() on the server as well
    # now() didn't work on the server either
    # in fact, pytz localize() (i.e. tz.localize(datetime.now()) seems broken
    # fortunately, astimezone() seems to work, so we are using it here

    dateFormat = "%Y-%m-%d"
    # endPoint = "user/storyline/daily/%s?trackPoints=true" % ('20140303')
    endPoint_today = "user/storyline/daily/%s?trackPoints=true" % (datetime.now(pytz.utc).astimezone(tz).strftime(dateFormat))
    endPoint_yesterday="user/storyline/daily/%s?trackPoints=true" % ((datetime.now(pytz.utc).astimezone(tz)-timedelta(1)).strftime(dateFormat))
    result_today = m.get(token=access_token, endpoint = endPoint_today)
    result_yesterday=m.get(token=access_token, endpoint = endPoint_yesterday)
    logging.debug("result_today.type = %s, result_yesterday = %s" % (type(result_today), type(result_yesterday)))
    # logging.debug(json.dumps(result_yesterday))

    # result=result_today+result_yesterday
    processResult(user_uuid, result_today)
    processResult(user_uuid, result_yesterday)
示例#5
0
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import *
from pymongo import MongoClient
from get_database import get_uuid_db, get_moves_db, get_profile_db
from datetime import datetime

for entry in get_moves_db().find():
  print("%s -> %s" % (entry['user'], entry['uuid']))
  userEmail = entry['user']
  userUUID = entry['uuid']
  userUUIDEntry = \
    {
      'user_email': userEmail,
      'uuid': userUUID,
      'update_ts': datetime.now()
    }
  get_uuid_db().update({'user_email': userEmail}, userUUIDEntry, upsert=True)

  profileUpdateObj = {'user_id': userUUID, 'study_list': [], 'update_ts': datetime.now()}
  get_profile_db().update({'user_id': userUUID}, {'$set': profileUpdateObj}, upsert=True)

  get_moves_db().update({'uuid': userUUID}, {'$set': {'our_uuid': userUUID}})
  get_moves_db().update({'uuid': userUUID}, {'$unset': {'uuid': "", 'user': ""}})
  
示例#6
0
def deleteAllTokens(user):
  user_access_table = get_moves_db()
  user_access_table.remove({"our_uuid" : user})
示例#7
0
def getAccessToken(user):
  user_access_table = get_moves_db()
  user_records = []
  for user in user_access_table.find({'our_uuid' : user}):
    user_records.append(user)
  return user_records
示例#8
0
def deleteAllTokens(user):
    user_access_table = get_moves_db()
    user_access_table.remove({"our_uuid": user})
示例#9
0
def getAccessToken(user):
    user_access_table = get_moves_db()
    user_records = []
    for user in user_access_table.find({'our_uuid': user}):
        user_records.append(user)
    return user_records