Skip to content

Instantly share code, notes, and snippets.

@ibrahim4851
Created July 4, 2022 18:45
Show Gist options
  • Save ibrahim4851/04b8337fbf62af706ceddec98a89be67 to your computer and use it in GitHub Desktop.
Save ibrahim4851/04b8337fbf62af706ceddec98a89be67 to your computer and use it in GitHub Desktop.
This script allows you to get the NBA teams' colors in xml format. You need to download requests library for python.
import requests
import json
import string
def getTeamColorData(url):
r = requests.get(url)
data = r.json()
for item in data:
erasArray = item['eras'][0]['colors']
print(item['name'])
name = "<!--" + item['name'] + " Color-->"
print(name)
for color in erasArray:
colorName = color['name']
colorName = colorName.translate({ord(c): None for c in string.whitespace})
xmlColor = '''<color name="{}">{}</color>'''.format(colorName, color['hex'])
print(xmlColor)
print("\n")
url = "https://api.teamhex.dev/leagues/nba"
getTeamColorData(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment