def store_api_user(user_id): try: url = API_URL + 'conf/' api_user = requests.get(url, headers={'authorization': 'JWT ' + get_api_token(user_id)}).json().get('username') REDIS.hset(user_id, 'api_user', api_user) except Exception as e: logger.warn('Failed store api_user for "%s": %s' % (user_id, e))
def store_resource(resource, user_id): try: url = API_URL + resource resources = requests.get(url, headers={'authorization': 'JWT ' + get_api_token(user_id)}).text.encode('utf-8') REDIS.hset(user_id, resource, resources) except Exception as e: logger.warn('Failed store resource "%s": %s' % (resource, e))
def store_resource(resource, user_id): try: url = API_URL + resource resources = requests.get(url, headers={ 'authorization': 'JWT ' + get_api_token(user_id) }).text.encode('utf-8') REDIS.hset(user_id, resource, resources) except Exception as e: logger.warn('Failed store resource "%s": %s' % (resource, e))
def store_api_user(user_id): try: url = API_URL + 'conf/' api_user = requests.get(url, headers={ 'authorization': 'JWT ' + get_api_token(user_id) }).json().get('username') REDIS.hset(user_id, 'api_user', api_user) except Exception as e: logger.warn('Failed store api_user for "%s": %s' % (user_id, e))
def store_transaction_to(to, user_id): REDIS.hset('%s:transaction' % user_id, 'to', to)
def store_transaction_from(fr, user_id): REDIS.hset('%s:transaction' % user_id, 'from', fr)
def store_transaction_kind(kind, user_id): kinds_map = {'income': 'inc', 'expense': 'exp', 'transfer': 'trn'} REDIS.hset('%s:transaction' % user_id, 'kind', kinds_map[kind])
def get_stored_resource(resource, user_id): return json.loads(REDIS.hget(user_id, resource))
def flush_transaction_fields(user_id): REDIS.delete('%s:transaction' % user_id)
def store_transaction_amount(amount, user_id): REDIS.hset('%s:transaction' % user_id, 'amount', amount)
def get_api_token(user_id): return REDIS.hget(user_id, 'token')