Created
July 4, 2022 18:45
-
-
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.
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
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