-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
70 lines (57 loc) · 1.83 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
import requests
from datetime import datetime
import os
GENDER = "YOUR_GENDER"
WEIGHT_KG = "YOUR_WEIGHT"
HEIGHT_CM = "YOUR_HEIGHT"
AGE = "YOUR_aGE"
APP_ID = os.environ['APP_ID']
API_KEY = os.environ['API_KEY']
exercise_endpoint = "https://trackapi.nutritionix.com/v2/natural/exercise"
sheet_endpoint = os.environ['SHEET_ENDPOINT']
exercise_text = input("Tell me which exercises you did: ")
headers = {
"x-app-id": APP_ID,
"x-app-key": API_KEY,
}
parameters = {
"query": exercise_text,
"gender": GENDER,
"weight_kg": WEIGHT_KG,
"height_cm": HEIGHT_CM,
"age": AGE
}
response = requests.post(exercise_endpoint, json=parameters, headers=headers)
result = response.json()
print(result)
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"]
}
}
#No Auth
sheet_response = requests.post(sheet_endpoint, json=sheet_inputs)
USERNAME = os.environ['USERNAME']
PASSWORD = os.environ['PASSWORD']
#Basic Auth
sheet_response = requests.post(sheet_endpoint,
json=sheet_inputs,
auth=(
USERNAME,
PASSWORD,
))
#Bearer Token
bearer_headers = {
"Authorization": os.environ['AUTHORIZATION']
}
sheet_response = requests.post(sheet_endpoint,
json=sheet_inputs,
headers=bearer_headers)
print(sheet_response.text)