File tree Expand file tree Collapse file tree 1 file changed +61
-0
lines changed
Workout_tracking_using_googlesheet Expand file tree Collapse file tree 1 file changed +61
-0
lines changed Original file line number Diff line number Diff line change 1+ import os
2+ from tkinter .constants import CURRENT
3+
4+ import dotenv
5+ import requests
6+ import time
7+
8+ Current_Date = time .strftime ("%Y/%m/%d" )
9+ Current_Time = time .strftime ("%H:%M:%S" )
10+
11+
12+ dotenv .load_dotenv ()
13+
14+ API_KEY = os .getenv ("API_KEY" )
15+ APP_ID = os .getenv ("APP_ID" )
16+ print (f"API_KEY: { API_KEY } , APP_ID: { APP_ID } " )
17+
18+ url = "https://trackapi.nutritionix.com/v2/natural/exercise"
19+
20+ query = input ("What do you want to do: " )
21+ print (f"User Input: { query } " )
22+
23+ headers = {
24+ "x-app-id" : APP_ID ,
25+ "x-app-key" : API_KEY ,
26+ "Content-Type" : "application/json"
27+ }
28+
29+ parameters = {
30+ "query" : query ,
31+ "gender" : "male" ,
32+ "weight_kg" : 72 ,
33+ "height_cm" : 172 ,
34+ "age" : 24
35+ }
36+
37+ response = requests .post (url , json = parameters , headers = headers )
38+
39+ print (f"Status Code: { response .status_code } " )
40+ print ("Response JSON:" )
41+ result = response .json ()
42+ print (result )
43+
44+ # For post data on google sheet.
45+
46+ for exercise in result ["exercises" ]:
47+ body = {
48+ "workout" :{
49+ "Date" : Current_Date ,
50+ "Time" : Current_Time ,
51+ "exercise" : exercise ["name" ].title (),
52+ "duration" : exercise ["duration_min" ],
53+ "calories" : exercise ["nf_calories" ]
54+ }
55+ }
56+
57+ google_sheet = os .getenv ("post_url" )
58+
59+ response_sheet = requests .post (google_sheet , json = body )
60+
61+ print (response_sheet .text )
You can’t perform that action at this time.
0 commit comments