-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day 38 - Workout Tracker
54 lines (41 loc) · 1.33 KB
/
Day 38 - Workout Tracker
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
#Day 38: Write code that will use Nutritionix to log exercise workouts and upload them automatically to a spreadsheet on Sheety.
import requests
from datetime import datetime
import os
GENDER = "female"
WEIGHT = 59
HEIGHT = 152
AGE = 27
APP_ID = os.environ[redacted]
API_KEY = os.environ[redacted]
exercise_endpoint = "https://trackapi.nutritionix.com/v2/natural/exercise"
params = {
"query": input("Tell me which exercises you did: "),
"gender": GENDER,
"weight_kg": WEIGHT,
"height_cm": HEIGHT,
"age": AGE
}
headers = {
"x-app-id": APP_ID,
"x-app-key": API_KEY
}
response = requests.post(url=exercise_endpoint, json=params, headers=headers)
result = response.json()
post_sheety_endpoint = "https://api.sheety.co/5e3aa5ed7d062b19b2ca0bd640f5c137/myWorkouts/workouts"
sheety_headers = {
"Authorization": f"Basic {os.environ[redacted]}"
}
today = datetime.now()
for x in result['exercises']:
exercise_params = {
"workout": {
"date": today.strftime("%d/%m/%Y"),
"time": today.strftime("%H:%M:%S"),
"exercise": x['name'].title(),
"duration": x['duration_min'],
"calories": x['nf_calories']
}
}
sheety_response = requests.post(url=post_sheety_endpoint, json=exercise_params, headers=sheety_headers)
print(sheety_response.text)