Having a play around with the Pimoroni Cat Facts example code, and noticed there’s also cat breeds data available too.
"""
Get a cat fact from t'internet!
You will need to add your wireless SSID and password to secrets.py (and save this file to your Pico)
"""
import requests
from time import sleep
# request = requests.get('http://catfact.ninja/fact').json()
# fact = request['fact']
# print('Cat fact!')
# print(fact)
request = requests.get('http://catfact.ninja/breeds').json()
breed = request['data']['breed']
for x in breed:
print(x)
#print('Cat breed :')
#print(fact)
Error reads: TypeError: list indices must be integers or slices, not str
Change breed = request['data']['breed']
to breed = request['data']
and I get all the JSON data
{'breed': 'Abyssinian', 'country': 'Ethiopia', 'origin': 'Natural/Standard', 'coat': 'Short', 'pattern': 'Ticked'}
{'breed': 'Aegean', 'country': 'Greece', 'origin': 'Natural/Standard', 'coat': 'Semi-long', 'pattern': 'Bi- or tri-colored'}
{'breed': 'American Curl', 'country': 'United States', 'origin': 'Mutation', 'coat': 'Short/Long', 'pattern': 'All'}
{'breed': 'American Bobtail', 'country': 'United States', 'origin': 'Mutation', 'coat': 'Short/Long', 'pattern': 'All'}
How do I code the python to get just breed names, or any other attribute?
Thank you.