Skip to content

Instantly share code, notes, and snippets.

@idling-mind
Created July 29, 2020 22:01
Show Gist options
  • Save idling-mind/87733d15459bc82bb64c9ae6411e96f7 to your computer and use it in GitHub Desktop.
Save idling-mind/87733d15459bc82bb64c9ae6411e96f7 to your computer and use it in GitHub Desktop.
Getting a top pallet from colorlovers.com
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