First load you credentials into a dict with:
import json
path = "Creds.json"
file = open(path)
content= file.read()
credentials = json.loads(content)
Then you have your input:
choice = input("Which account credentials do you want to use: ")
print("Press 1 for Account 1")
print("Press 2 for Account 2")
print("Press 3 for Account 3")
And finally gather your crendential with:
credential = credentials["Account{0}".format(int(choice))]
You have to correct your file Creds.json
:
{
"Account1":{
"client_token" : "12345678",
"client_secret" : "9865432",
"access_token": "3459865"
},
"Account2":{
"client_token" : "33456787",
"client_secret" : "23456787",
"access_token": "98654378"
},
"Account3":{
"client_token" : "1234567",
"client_secret" : "87654378",
"access_token": "35627826"
}
}
You can correct you Cred.json with this script:
content = open("Creds.json").read()
content = content.replace("'", '"')
content = content.replace("}
", '},')
content = "{" + content + "}"
credentials = json.loads(content)
And here in production version
import json
credentials = json.loads("{" + open("Creds.json").read().replace("'", '"').replace("}
", '},') + "}")
while True:
choice = input("Which account credentials do you want to use:" + "".join("
Press {0} for {0}".format(i + 1, credential) for i, credential in enumerate(credentials))+"
")
key = "Account{0}".format(int(choice))
if key in credentials:
break
else:
print("Wrong answer, please retry (CRTC + C to exit)")
credential = credentials[key]
print(credential)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…