Public Access
70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
import json
|
|
import os
|
|
from datetime import date
|
|
from getpass import getpass
|
|
|
|
from garminconnect import Garmin
|
|
|
|
|
|
TOKENSTORE = os.path.join(os.path.dirname(__file__), ".garmin_tokens")
|
|
|
|
|
|
def dump(title, data):
|
|
print()
|
|
print("=" * 70)
|
|
print(title)
|
|
print("=" * 70)
|
|
print(json.dumps(data, indent=2, ensure_ascii=False, default=str))
|
|
|
|
|
|
def main():
|
|
email = input("Garmin email: ").strip()
|
|
password = getpass("Garmin password: ")
|
|
|
|
garmin = Garmin(
|
|
email=email,
|
|
password=password,
|
|
)
|
|
|
|
os.makedirs(TOKENSTORE, exist_ok=True)
|
|
|
|
print("\nLoggar in mot Garmin Connect...")
|
|
|
|
result = garmin.login(TOKENSTORE)
|
|
|
|
print("Inloggning OK.")
|
|
print("Display name:", garmin.display_name)
|
|
|
|
today = date.today().isoformat()
|
|
|
|
print(f"\nHämtar Garmin-data för {today}...")
|
|
|
|
calls = [
|
|
("Daily stats", lambda: garmin.get_stats(today)),
|
|
("Heart rate", lambda: garmin.get_heart_rates(today)),
|
|
("Sleep", lambda: garmin.get_sleep_data(today)),
|
|
("HRV", lambda: garmin.get_hrv_data(today)),
|
|
("Stress", lambda: garmin.get_stress_data(today)),
|
|
("Body Battery", lambda: garmin.get_body_battery(today)),
|
|
("Respiration", lambda: garmin.get_respiration_data(today)),
|
|
("SpO2", lambda: garmin.get_spo2_data(today)),
|
|
("Training readiness", lambda: garmin.get_training_readiness(today)),
|
|
("Training status", lambda: garmin.get_training_status(today)),
|
|
("Activities", lambda: garmin.get_activities(0, 10)),
|
|
("Devices", lambda: garmin.get_devices()),
|
|
]
|
|
|
|
for title, fn in calls:
|
|
try:
|
|
data = fn()
|
|
dump(title, data)
|
|
except Exception as e:
|
|
print()
|
|
print("=" * 70)
|
|
print(title)
|
|
print("=" * 70)
|
|
print(f"ERROR: {type(e).__name__}: {e}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |