-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (59 loc) · 1.65 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
import json
import time
import os
from datetime import datetime
import schedule
import fitbit
def refresh(token):
print("Refreshing token")
with open("token.json", "w") as f:
f.write(json.dumps(token))
def main():
print("Reading token")
with open("token.json", "r") as f:
data = json.loads(f.read())
print("Creating client")
authd_client = fitbit.Fitbit(
os.environ["CLIENT_ID"],
os.environ["CLIENT_SECRET"],
access_token=data["access_token"],
refresh_token=data["refresh_token"],
expires_at=data["expires_at"],
refresh_cb=refresh,
system="en_AU",
)
print("Log Swim activity")
authd_client.log_activity(
{
"activityId": "90024",
"date": datetime.today().strftime("%Y-%m-%d"),
"startTime": "01:00",
"durationMillis": "3600000",
"distance": "10.0",
}
)
print("Log Meditating activity")
authd_client.log_activity(
{
"activityId": "52001",
"date": datetime.today().strftime("%Y-%m-%d"),
"startTime": "02:00",
"durationMillis": "3600000",
}
)
print("Log Yoga activity")
authd_client.log_activity(
{
"activityId": "7075",
"date": datetime.today().strftime("%Y-%m-%d"),
"startTime": "03:00",
"durationMillis": "3600000",
}
)
if __name__ == "__main__":
print("Creating schedule")
schedule.every(int(os.environ["INTERVAL"])).minutes.do(main)
while True:
schedule.run_pending()
time.sleep(1)