Skip to content

Commit ee83257

Browse files
Adding support for BMI and weight data fetching
1 parent e61e021 commit ee83257

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Fitbit_Fetch.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,35 @@ def get_daily_data_limit_30d(start_date_str, end_date_str):
363363
else:
364364
logging.error("Recording failed : SPO2 intraday for date " + start_date_str + " to " + end_date_str)
365365

366+
weight_data_list = request_data_from_fitbit('https://api.fitbit.com/1/user/-/body/log/weight/date/' + start_date_str + '/' + end_date_str + '.json')["weight"]
367+
if weight_data_list != None:
368+
for entry in weight_data_list:
369+
log_time = datetime.fromisoformat(entry["date"] + "T" + entry["time"])
370+
utc_time = LOCAL_TIMEZONE.localize(log_time).astimezone(pytz.utc).isoformat()
371+
collected_records.append({
372+
"measurement": "weight",
373+
"time": utc_time,
374+
"tags": {
375+
"Device": DEVICENAME
376+
},
377+
"fields": {
378+
"value": float(entry["weight"]),
379+
}
380+
})
381+
collected_records.append({
382+
"measurement": "bmi",
383+
"time": utc_time,
384+
"tags": {
385+
"Device": DEVICENAME
386+
},
387+
"fields": {
388+
"value": float(entry["bmi"]),
389+
}
390+
})
391+
logging.info("Recorded weight and BMI for date " + start_date_str + " to " + end_date_str)
392+
else:
393+
logging.error("Recording failed : weight and BMI for date " + start_date_str + " to " + end_date_str)
394+
366395
# Only for sleep data - limit 100 days - 1 query
367396
def get_daily_data_limit_100d(start_date_str, end_date_str):
368397

0 commit comments

Comments
 (0)