Created
July 29, 2020 22:01
-
-
Save idling-mind/87733d15459bc82bb64c9ae6411e96f7 to your computer and use it in GitHub Desktop.
Getting a top pallet from colorlovers.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xml.etree import ElementTree as et | |
import requests | |
def get_top_pallet(rank): | |
"""Get a top ranked pallete from colorlovers.com | |
Args: | |
rank (int): The rank of the pallet in the website. | |
Starting with 0. | |
Returns: | |
list: A list of str where each str is a hex representation | |
of the color | |
""" | |
# Using requests module to get the top pallets xml | |
r = requests.get("https://www.colourlovers.com/api/palettes/top") | |
# Parsing the xml to return the pallet based on input rank | |
pallets = et.fromstring(r.text) | |
# Getting the hex tags from a given pallet | |
hex_elems = pallets[rank].iter('hex') | |
return [c.text for c in hex_elems] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment