-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
48 lines (40 loc) · 1.24 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import streamlit as st
import numpy as np
import os
import garminconnect
import streamlit_backend as sb
import json
from datetime import date, timedelta
st.title("Sleep Data")
st.subheader("Duration of study")
# Create weekly df
col1, col2 = st.columns(2)
with col1:
END_DATE = st.date_input("Select last observed date", value=date(2023, 12, 31))
with col2:
DURATION = st.number_input("Duration", value=31)
st.subheader("Login")
# LOGIN container
col1, col2 = st.columns(2)
with col1:
email = st.text_input("Enter email address")
with col2:
password = st.text_input("Enter password:", type="password")
login_verify = st.button("Login", type="primary")
if login_verify:
garmin = sb.login(email, password)
# Remove password to prevent continuously API request
password = ""
if login_verify:
dataframe = sb.get_sleep_data(garmin, end_date=END_DATE, duration=DURATION)
st.write(dataframe)
st.subheader("Save the file")
# Option to save the dataframe as JSON
json_string = dataframe.to_json(orient='records', lines=True)
# Download button to download JSON
st.download_button(
label="Download data as JSON",
file_name='sleep_data.json',
mime='application/json',
data=json_string
)