I'm currently playing with the MCC API and I want to put every players name in their own text file within their team folder. This is the code that I have currently:
import requests
r = requests.get("https://api.mcchampionship.com/v1/participants")
# TEAMS
# RED
# Player 1
DATA_Red_p1 = open("./Players/Red/player1.txt", "w")
DATA_Red_p1.write(str(r.json()['data']['RED'][0]['username']))
DATA_Red_p1.close()
# Player 2
DATA_Red_p2 = open("./Players/Red/player2.txt", "w")
DATA_Red_p2.write(str(r.json()['data']['RED'][1]['username']))
DATA_Red_p2.close()
# Player 3
# ...
# Player 4
# ...
I have the same code copy and pasted (excluding the import and the api fetch) for each team, just with different variables and file paths. The teams are: Red, orange, yellow, lime, green, cyan, aqua, blue, purple and pink. I was just wondering if there was an easier way of writing the code.