-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
55 lines (48 loc) · 1.42 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
import requests
from datetime import datetime
import os
GENDER = os.environ.get("YOUR_GENDER")
AGE = os.environ.get("YOUR_AGE")
WEIGHT= os.environ.get("YOUR_WEIGHT")
HEIGHT= os.environ.get("YOUR_HEIGHT")
NUTRI_APP_ID = os.environ.get("APP_ID")
NUTRI_API_KEY = os.environ.get("API_KEY")
EXERCISE_ENDPOINT= "https://trackapi.nutritionix.com/v2/natural/exercise"
SHEET_ENDPOINT = os.environ.get("SHEET_ENDPOINT")
BEARER_TOKEN = os.environ.get("TOKEN")
#TODO post exercise to nutrition
exercise_params = {
"query": input("What did you do today? "),
"gender": GENDER,
"height_cm": HEIGHT,
"weight_kg": WEIGHT,
"age": AGE
}
header = {
"x-app-id": NUTRI_APP_ID,
"x-app-key": NUTRI_API_KEY,
}
response = requests.post(url=EXERCISE_ENDPOINT, json=exercise_params, headers=header)
result = response.json()
print(result)
#TODO save results to google sheets
today = datetime.now()
date = today.strftime("%d/%m/%Y")
time = today.strftime("%X")
exercise = result["exercises"][0]["name"]
duration = result["exercises"][0]["duration_min"]
calories = result["exercises"][0]["nf_calories"]
add_paramas = {
"workout": {
"date":date,
"time":time,
"exercise":exercise.title(),
"duration":duration,
"calories":calories
}
}
token = {
"Authorization": f"Bearer {BEARER_TOKEN}"
}
add_data = requests.post(url=SHEET_ENDPOINT, json=add_paramas, headers= token)
sheet_response = add_data.json()