Python Co using the Dog API @ https://dog.ceo/dog-api/

  Kiến thức lập trình

I have a problem with my Python code, I am trying to figure out how to add something to my code. I want to add a request to the Dog API for images of all dogs of a given breed, in this case,
it’s poodles. I also want to make a version in which 1 image of a poodle is retrieved and saved in the folder of my script.

I’m quite new to coding, so I thought instead of using ChatGPT, I would ask for help with my problem here. If there are any other good sources of information I can use to help with coding, let me know. 🙂

This is my code:

import urllib.request
import json

def all_dog_breeds():
    url1 = "https://dog.ceo/api/breeds/list/all"
    response = urllib.request.urlopen(url1)
    data = json.loads(response.read().decode())
    response.close()  
    return data
    
    
breeds_data1 = all_dog_breeds()
# Extract breed names from the data
breed_names = breeds_data1['message'].keys()

# Print the breed names
for breed_name in breed_names:
    print(breed_name)


def random_picture():
    url2 = "https://dog.ceo/api/breeds/image/random"
    response = urllib.request.urlopen(url2)
    data = json.loads(response.read().decode())
    response.close()  
    return data
    
    
breeds_data2 = random_picture()
print(breeds_data2)

I tried to figure it out on my own, but with no luck. ChatGPT seems like too easy of a solution. If you know any other good sources of information to help with this kind of thing, let me know.

New contributor

Python_Beginner23 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT