get the last 10 votes from https://api.thecatapi.com/v1/votes?limit=10&order=desc in python

To get the last 10 votes from the given URL in python, you can use the requests module to make HTTP GET request to the URL and json module to parse the JSON response from the API. Here's the code:

main.py
import requests
import json

url = "https://api.thecatapi.com/v1/votes?limit=10&order=desc"

response = requests.get(url)

if response.ok:
    votes = json.loads(response.text)
    for vote in votes:
        print(vote)
else:
    print("Failed to get the votes.")
264 chars
14 lines

The above code will make HTTP GET request to the given URL and parse the JSON response using json.loads() method. It will iterate through the last 10 votes and print each vote object.

related categories

gistlibby LogSnag