-
-
Save angelabauer/dd71d7072626afd728e1730584c6e4b8 to your computer and use it in GitHub Desktop.
import requests | |
GENDER = YOUR GENDER | |
WEIGHT_KG = YOUR WEIGHT | |
HEIGHT_CM = YOUR HEIGHT | |
AGE = YOUR AGE | |
APP_ID = YOUR APP ID | |
API_KEY = YOUR API KEY | |
exercise_endpoint = "https://trackapi.nutritionix.com/v2/natural/exercise" | |
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) |
import requests
NUTRITION_API_KEY = "API KEY"
NUTRITION_NATURAL_ENDPOINT = "https://trackapi.nutritionix.com/v2/natural/exercise"
APP_ID = "APP ID"
headers = {
'Content-Type': 'application/json',
"x-app-id": f"{APP_ID}",
"x-app-key": f"{NUTRITION_API_KEY}"
}
parameters = {
"query": input("What Exercise You Just Did: ")
}
nutrition = requests.post(url=NUTRITION_NATURAL_ENDPOINT, json=parameters, headers=headers)
print(nutrition.json())
OUTPUT:
WhatExerciseYouJustDid: Cricket{
'exercises': [
{
'tag_id': 215,
'user_input': 'cricket',
'duration_min': 30,
'met': 4.8,
'nf_calories': 168,
'photo': {
'highres': 'https://d2xdmhkmkbyw75.cloudfront.net/exercise/215_highres.jpg',
'thumb': 'https://d2xdmhkmkbyw75.cloudfront.net/exercise/215_thumb.jpg',
'is_user_uploaded': False
},
'compendium_code': 15150,
'name': 'cricket',
'description': None,
'benefits': None
}
]
}
`import requests
APP_ID = "7bceec16"
APP_KEY = "844902aaedb6f200acca45f3e3364288"
GENDER = "Male"
AGE = "20"
WEIGHT_KG = "65"
HEIGHT_CM = "175"
exercise_endpoint = "https://trackapi.nutritionix.com/v2/natural/exercise"
exercise_text = input("Tell me which exercise did you do? ")
headers = {
"x-app-id": APP_ID,
"x-app-key": APP_KEY,
"Content-Type": "application/json"
}
parameters = {
"query": exercise_text,
"gender": GENDER,
"weight_kg": WEIGHT_KG,
"height_cm": HEIGHT_CM,
"age": AGE
}
response = requests.get(url=exercise_endpoint, json=parameters, headers=headers)
response.raise_for_status()
tried this code a lot made many changes and yet getting this output
OUTPUT
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://trackapi.nutritionix.com/v2/natural/exercise`
`import requests
APP_ID = "7bceec16" APP_KEY = "844902aaedb6f200acca45f3e3364288" GENDER = "Male" AGE = "20" WEIGHT_KG = "65" HEIGHT_CM = "175"
exercise_endpoint = "https://trackapi.nutritionix.com/v2/natural/exercise"
exercise_text = input("Tell me which exercise did you do? ") headers = { "x-app-id": APP_ID, "x-app-key": APP_KEY, "Content-Type": "application/json" } parameters = { "query": exercise_text, "gender": GENDER, "weight_kg": WEIGHT_KG, "height_cm": HEIGHT_CM, "age": AGE }
response = requests.get(url=exercise_endpoint, json=parameters, headers=headers) response.raise_for_status()
tried this code a lot made many changes and yet getting this output
OUTPUT raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://trackapi.nutritionix.com/v2/natural/exercise`
use GENDER = 'male'
AGE = 20 int not str
weight_kg = 65 same int not str
height_cm = 175
then save response in new variable data or results
data = response.json()
print(data)
import requests APP_ID = "7bceec16" APP_KEY = "844902aaedb6f200acca45f3e3364288" GENDER = "Male" AGE = "20" WEIGHT_KG = "65" HEIGHT_CM = "175" exercise_endpoint = "https://trackapi.nutritionix.com/v2/natural/exercise" exercise_text = input("Tell me which exercise did you do? ") headers = { "x-app-id": APP_ID, "x-app-key": APP_KEY, "Content-Type": "application/json" } parameters = { "query": exercise_text, "gender": GENDER, "weight_kg": WEIGHT_KG, "height_cm": HEIGHT_CM, "age": AGE } response = requests.get(url=exercise_endpoint, json=parameters, headers=headers) response.raise_for_status() tried this code a lot made many changes and yet getting this output **OUTPUT** raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 404 Client Error: Not Found for url: [https://trackapi.nutritionix.com/v2/natural/exercise
](https://trackapi.nutritionix.com/v2/natural/exercise%60)use GENDER = 'male' AGE = 20 int not str weight_kg = 65 same int not str height_cm = 175 then save response in new variable data or results data = response.json() print(data)
still the same no changes
I think I found the answer....thank you