<jupyter_start><jupyter_text>This sets up the connect to the fitbit server. All data needed can be called from auth2_client.<jupyter_code>import fitbit
import gather_keys_oauth2 as Oauth2
import pandas as pd 
import datetime

CLIENT_ID = '22D58N'
CLIENT_SECRET = '8d0f0ce5f500a4c3f3655cfa7744d084'

server = Oauth2.OAuth2Server(CLIENT_ID, CLIENT_SECRET)
server.browser_authorize()

ACCESS_TOKEN = str(server.fitbit.client.session.token['access_token'])
REFRESH_TOKEN = str(server.fitbit.client.session.token['refresh_token'])

auth2_client = fitbit.Fitbit(CLIENT_ID, CLIENT_SECRET, oauth2=True, access_token=ACCESS_TOKEN, refresh_token=REFRESH_TOKEN)<jupyter_output>[03/Nov/2018:20:46:27] ENGINE Listening for SIGTERM.
[03/Nov/2018:20:46:27] ENGINE Listening for SIGHUP.
[03/Nov/2018:20:46:27] ENGINE Listening for SIGUSR1.
[03/Nov/2018:20:46:27] ENGINE Bus STARTING
CherryPy Checker:
The Application mounted at '' has an empty config.

[03/Nov/2018:20:46:27] ENGINE Started monitor thread 'Autoreloader'.
[03/Nov/2018:20:46:27] ENGINE Serving on http://127.0.0.1:8080
[03/Nov/2018:20:46:27] ENGINE Bus STARTED<jupyter_text>This is getting all the days that weight was recorded (roughly ever 15 days). Then it stores it into a csv file for processing later.<jupyter_code>#today = str(datetime.datetime.now().strftime("%Y%m%d"))
yesterday = str((datetime.datetime.now() - datetime.timedelta(days=1)).strftime("%Y%m%d"))


weights = pd.DataFrame(columns=['Date','Weight'])
for h in range(6,11): #do 1,6 first
    for i in range(1,32):
        if((h != 2 or (i < 29)) and ((h!=4 and h!=6 and h!=9 and h!=11) or (i < 31))):
            day_weight = auth2_client.body(date='2018-' + str(h) + '-' + str(i))["body"]["weight"]
            if(day_weight != 0):
                print(day_weight)
                print("Date: " + str(h) + "-" + str(i) + "-2018")
                temp = pd.DataFrame([["2018-" + str(h) + "-" + str(i), day_weight]], columns=['Date','Weight'])
                weights = weights.append(temp)
                
weights.to_csv("weights2.csv")
                
#Calories
#print(auth2_client.activities(date='2018-10-31')["summary"]["caloriesOut"])
#for i in range (1,32):
 # print(auth2_client.activities(date='2018-10-' + str(i))["summary"]["caloriesOut"])
print(auth2_client.body(date="2018-10-29")["body"]["bmi"])<jupyter_output>27.33
{'fraction_non_alphanumeric': 0.1602891156462585, 'fraction_numerical': 0.0824829931972789, 'mean_word_length': 4.575829383886256, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '444475', 'license': 'Apache-2.0', 'n_tokens_mistral': 989, 'n_tokens_neox': 866, 'n_words': 176, 'path': 'Untitled.ipynb', 'repo_name': 'CCrisanti/healthhacks2018', 'size': '2352'}