File tree 1 file changed +59
-0
lines changed
1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ import requests
2
+ from datetime import datetime
3
+
4
+ APP_ID = "***"
5
+ API_KEY = "*** "
6
+
7
+ base_url = "https://trackapi.nutritionix.com/"
8
+
9
+ exercise_endpoint = "v2/natural/exercise"
10
+
11
+ natural_language_endpoint = "v2/natural/nutrients"
12
+
13
+ exercise_text = input ("Tell me which exercises you did: " )
14
+
15
+ headers = {
16
+ 'Content-Type' : 'application/json' ,
17
+ 'x-app-id' : APP_ID ,
18
+ 'x-app-key' : API_KEY
19
+ }
20
+
21
+ parameters = {
22
+ "query" : exercise_text ,
23
+ "gender" : "Female" ,
24
+ "weight_kg" : "76" ,
25
+ "height_cm" : "175" ,
26
+ "age" : "29"
27
+ }
28
+
29
+ exercise_api = "https://trackapi.nutritionix.com/v2/natural/exercise"
30
+
31
+ response = requests .post (exercise_api , json = parameters , headers = headers )
32
+ result = response .json ()
33
+ print (result )
34
+
35
+ ################### Start of Step 4 Solution ######################
36
+ sheet_endpoint = "https://api.sheety.co/dfc12b16014e0535ccc53faaf6530e37/myWorkoutsAlbin/workouts"
37
+ today_date = datetime .now ().strftime ("%d/%m/%Y" )
38
+ now_time = datetime .now ().strftime ("%X" )
39
+
40
+ bearer_headers = {
41
+ "Authorization" : "Bearer *****"
42
+ }
43
+
44
+ for exercise in result ["exercises" ]:
45
+ sheet_inputs = {
46
+ "workout" : {
47
+ "date" : today_date ,
48
+ "time" : now_time ,
49
+ "exercise" : exercise ["name" ].title (),
50
+ "duration" : exercise ["duration_min" ],
51
+ "calories" : exercise ["nf_calories" ]
52
+ }
53
+ }
54
+
55
+
56
+
57
+ sheet_response = requests .post (sheet_endpoint , json = sheet_inputs , headers = bearer_headers )
58
+
59
+ print (sheet_response .text )
You can’t perform that action at this time.
0 commit comments