Esempio n. 1
0
def loadFB():
    # see: http://python-fitbit.readthedocs.org/en/latest/#fitbit-api
    fb = fitbit.Fitbit(
        os.getenv('CONSUMER_KEY'),
        os.getenv('CONSUMER_SECRET'), 
        user_key=os.getenv('USER_KEY'),
        user_secret=os.getenv('USER_SECRET'))
    
    redis.delete('fitbit')
    
    if True:
        sleepData = dict();
        sl1 = fb.time_series('sleep/startTime', period='max')['sleep-startTime']
        sl2 = fb.time_series('sleep/timeInBed', period='max')['sleep-timeInBed']
        sl3 = fb.time_series('sleep/minutesAsleep', period='max')['sleep-minutesAsleep']
        sl4 = fb.time_series('sleep/minutesAwake', period='max')['sleep-minutesAwake']
        sl5 = fb.time_series('sleep/minutesToFallAsleep', period='max')['sleep-minutesToFallAsleep']
        sl6 = fb.time_series('sleep/minutesAfterWakeup', period='max')['sleep-minutesAfterWakeup']
        sl7 = fb.time_series('sleep/efficiency', period='max')['sleep-efficiency']
        
        for sl in range(len(sl1)-1):            
            if sl1[sl]['value'] != '':                
                tempdate = datetime.datetime.strptime(sl1[sl]['dateTime'], '%Y-%m-%d').timetuple()
                sleepData['date'] = time.mktime(tempdate)
                temptime = time.strptime((sl1[sl]['dateTime'] + '-' + sl1[sl]['value']), '%Y-%m-%d-%H:%M')
                sleepData['startTime'] = time.mktime(temptime)
                sleepData['timeInBed'] = sl2[sl]['value']
                sleepData['minutesAsleep'] = sl3[sl]['value']
                sleepData['minutesAwake'] = sl4[sl]['value']
                sleepData['minutesToFallAsleep'] = sl5[sl]['value']
                sleepData['minutesAfterWakeup'] = sl6[sl]['value']
                sleepData['efficiency'] = sl7[sl]['value']
                s = json.dumps(sleepData)
                redis.sadd('fitbit', s)
                print s
Esempio n. 2
0
def unlink():
    fbId = getFbId()
    if not fbId:
        return "", 403
    key = redis.get(fbId)
    redis.delete(fbId)
    plaid = Plaid(PLAID_ID, PLAID_KEY, key)
    plaid.delete()
    return redirect("/", code=302)
Esempio n. 3
0
def load():

    # see: http://python-fitbit.readthedocs.org/en/latest/#fitbit-api
    fb = fitbit.Fitbit(
        os.getenv("CONSUMER_KEY"),
        os.getenv("CONSUMER_SECRET"),
        user_key=os.getenv("USER_KEY"),
        user_secret=os.getenv("USER_SECRET"),
    )

    redis.delete("fitbit")

    if True:
        sleepData = dict()
        sl1 = fb.time_series("sleep/startTime", period="max")["sleep-startTime"]
        sl2 = fb.time_series("sleep/timeInBed", period="max")["sleep-timeInBed"]
        sl3 = fb.time_series("sleep/minutesAsleep", period="max")["sleep-minutesAsleep"]
        sl4 = fb.time_series("sleep/minutesAwake", period="max")["sleep-minutesAwake"]
        sl5 = fb.time_series("sleep/minutesToFallAsleep", period="max")["sleep-minutesToFallAsleep"]
        sl6 = fb.time_series("sleep/minutesAfterWakeup", period="max")["sleep-minutesAfterWakeup"]
        sl7 = fb.time_series("sleep/efficiency", period="max")["sleep-efficiency"]

        for sl in range(len(sl1)):
            if sl1[sl]["value"] != "":
                sleepData["date"] = sl1[sl]["dateTime"]
                sleepData["startTime"] = sl1[sl]["value"]
                sleepData["timeInBed"] = sl2[sl]["value"]
                sleepData["minutesAsleep"] = sl3[sl]["value"]
                sleepData["minutesAwake"] = sl4[sl]["value"]
                sleepData["minutesToFallAsleep"] = sl5[sl]["value"]
                sleepData["minutesAfterWakeup"] = sl6[sl]["value"]
                sleepData["efficiency"] = sl7[sl]["value"]
                sleepData["timezone"] = fb.user_profile_get()["user"]["timezone"]
                sleepData["offsetFromUTCMillis"] = fb.user_profile_get()["user"]["offsetFromUTCMillis"]
                s = json.dumps(sleepData)
                redis.sadd("fitbit", s)
                print s
Esempio n. 4
0
def load():

    # see: http://python-fitbit.readthedocs.org/en/latest/#fitbit-api
    fb = fitbit.Fitbit(
        os.getenv('CONSUMER_KEY'),
        os.getenv('CONSUMER_SECRET'), 
        user_key=os.getenv('USER_KEY'),
        user_secret=os.getenv('USER_SECRET'))
    
    redis.delete('fitbit')
    
    if True:
        sleepData = dict();
        sl1 = fb.time_series('sleep/startTime', period='max')['sleep-startTime']
        sl2 = fb.time_series('sleep/timeInBed', period='max')['sleep-timeInBed']
        sl3 = fb.time_series('sleep/minutesAsleep', period='max')['sleep-minutesAsleep']
        sl4 = fb.time_series('sleep/minutesAwake', period='max')['sleep-minutesAwake']
        sl5 = fb.time_series('sleep/minutesToFallAsleep', period='max')['sleep-minutesToFallAsleep']
        sl6 = fb.time_series('sleep/minutesAfterWakeup', period='max')['sleep-minutesAfterWakeup']
        sl7 = fb.time_series('sleep/efficiency', period='max')['sleep-efficiency']
        
        for sl in range(len(sl1)):            
            if sl1[sl]['value'] != '':                
                sleepData['date'] = sl1[sl]['dateTime']
                sleepData['startTime'] = sl1[sl]['value']
                sleepData['timeInBed'] = sl2[sl]['value']
                sleepData['minutesAsleep'] = sl3[sl]['value']
                sleepData['minutesAwake'] = sl4[sl]['value']
                sleepData['minutesToFallAsleep'] = sl5[sl]['value']
                sleepData['minutesAfterWakeup'] = sl6[sl]['value']
                sleepData['efficiency'] = sl7[sl]['value']
                sleepData['timezone'] = fb.user_profile_get()['user']['timezone']
                sleepData['offsetFromUTCMillis'] = fb.user_profile_get()['user']['offsetFromUTCMillis']
                s = json.dumps(sleepData)
                redis.sadd('fitbit', s)
                print s
Esempio n. 5
0
def delete_book_isbn(isbn):
    clear_caches()
    rfid_id = redis.delete(isbn+":rfid_num")
    redis.delete(isbn+":on_shelf")
    book_title = redis.get(isbn+":book_title")
    redis.delete(isbn+":book_title")
    redis.delete(isbn+":author")
    redis.delete(isbn+":pic_url")
    try:
        redis.delete('rfid_id:'+rfid_id)
    except:
        pass