Example #1
0
def index():
    form = DeviceUserForm(request.form)
    creds = get_all_fitbit_credentials()
    user_profiles = []
    user_state = request.args.get('state')
    
    if user_state:
        perm_url = get_permission_screen_url(user_state)
    else:
        perm_url = None
    
    for cred in creds:
        with fitbit_client(cred) as client:
            try:
                profile_response = client.user_profile_get()
                user_profiles.append({
                    'username': cred.user_id,
                    'fullName': profile_response['user']['fullName']
                })
            except BadResponse:
                flash("Api Call Failed") 
            except InvalidGrantError:
                user_profiles.append({
                    'username': cred.user_id,
                    'fullName': 'PROFILE LOAD FAILED PLEASE REAUTHENTICATE'
                })
                				
        
    return render_template('index.html',
                           user_state=user_state,
                           form=form,
                           user_profiles=user_profiles,
                           permission_url=perm_url)
Example #2
0
def index():
    if not flask_login.current_user.is_authenticated:
        return redirect(url_for('main.login'))
    else:
        user_profile = "Could not access fitbit profile"
        ls = 'Subscription List is Empty!'
        data = ''
        fitbit_creds = get_user_fitbit_credentials(flask_login.current_user.id)
        if fitbit_creds:
            with fitbit_client(fitbit_creds) as client:
                try:

                    profile_response = client.user_profile_get()
                    user_profile = "{} has been on fitbit since {}".format(
                        profile_response['user']['fullName'],
                        profile_response['user']['memberSince'])

                    #client.subscription(flask_login.current_user.id, '100')
                    #ls  = client.time_series('activities/calories', period='1y')
                    #ls = client.activity_stats()
                    #ls = client.list_subscriptions()
                    #pprint(ls)
                    #data = ls['activities-calories']

                except BadResponse:

                    flash("Api Call Failed")
        return render_template('index.html',
                               user_profile=user_profile,
                               permission_url=get_permission_screen_url())
Example #3
0
def index():
    if not flask_login.current_user.is_authenticated:
        return redirect(url_for('main.login'))
    else:
        user_profile = "Could not access fitbit profile"
        fitbit_creds = get_user_fitbit_credentials(flask_login.current_user.id)
        if fitbit_creds:
            with fitbit_client(fitbit_creds) as client:
                try:
                    profile_response = client.user_profile_get()
                    user_profile = "{} has been on fitbit since {}".format(
                        profile_response['user']['fullName'],
                        profile_response['user']['memberSince'])
                except BadResponse:
                    flash("Api Call Failed")
        return render_template('index.html',
                               user_profile=user_profile,
                               permission_url=get_permission_screen_url())