-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkout.py
60 lines (48 loc) · 1.33 KB
/
workout.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
import requests
from datetime import datetime
import os
GENERO = "male"
PESO = 71
ALTURA = 180
IDADE = 18
NUTRITIONIX_APP_ID = os.getenv("NUTRITIONIX_APP_ID")
NUTRITIONIX_API_KEY = os.getenv("NUTRITIONIX_API_KEY")
exercise_endpoint = "https://trackapi.nutritionix.com/v2/natural/exercise"
sheet_endpoint = os.getenv("sheet_endpoint")
exercise_text = input("Diga quais exercícios você realizou: ")
headers = {
"x-app-id": NUTRITIONIX_APP_ID,
"x-app-key": NUTRITIONIX_API_KEY,
}
parameters = {
"query": exercise_text,
"gender": GENERO,
"weight_kg": PESO,
"height_cm": ALTURA,
"age": IDADE
}
response = requests.post(exercise_endpoint, json=parameters, headers=headers)
result = response.json()
today_date = datetime.now().strftime("%d/%m/%Y")
now_time = datetime.now().strftime("%X")
for exercise in result["exercises"]:
sheet_inputs = {
"workout": {
"date": today_date,
"time": now_time,
"exercise": exercise["name"].title(),
"duration": exercise["duration_min"],
"calories": exercise["nf_calories"]
}
}
TOKEN = os.getenv("TOKEN")
#Bearer Token Authentication
bearer_headers = {
"Authorization": TOKEN
}
sheet_response = requests.post(
sheet_endpoint,
json=sheet_inputs,
headers=bearer_headers
)
print(sheet_response.text)