i am trying to add an email object to the testing accounts json. finding myself a little stuck on this.
ideally i would like to add an email field to the testing_accounts objects. 1 Per.
jsondata
testing_accounts = [{'tenantName': 'hsmd1012159', 'studentName': 'stu1012159', 'studentPassword': 'asdf123!'}, {'tenantName': 'hsmd1012716', 'studentName': 'stu1012716', 'studentPassword': 'asdf123!'}, {'tenantName': 'hsmd1011234', 'studentName': 'stu1011234', 'studentPassword': 'asdf123!'}]
item i would like to add to each json object above.
test = "asdf@gmail.com\nasdf123@gmail.com\ntest@gmail.com"
The other catch is if there are not enough emails to match the tenants then add a "null@null.com"
Desired output
desiredOutput = [{
'tenantName': 'hsmd1012159', 'studentName': 'stu1012159', 'studentPassword': 'asdf123!', 'email': 'asdf@gmail.com'
},
{
'tenantName': 'hsmd1012716', 'studentName': 'stu1012716', 'studentPassword': 'asdf123!', 'email': 'asdf123@gmail.com'
},
{
'tenantName': 'hsmd1011234', 'studentName': 'stu1011234', 'studentPassword': 'asdf123!' , 'email': 'test@gmail.com'
},
{
'tenantName': 'hsmd1011s2234', 'studentName': 'stu122011234', 'studentPassword': 'asdf123!' , 'email': 'null@null'
}
]
Where i am at so far....
print(len(testing_accounts))
print(testing_accounts)
def newline(string):
listRes = list(string.split("\n"))
return listRes
def comma(string):
listRes = list(string.split(","))
return listRes
def comma_and_space(string):
listRes = list(string.split(", "))
return listRes
if '\n' in test:
test1 = newline(test)
test1 = json.dumps(test1)
print(test1)
elif ',' in test:
test1 = comma(test)
test1 = json.dumps(test1)
print(test1)
elif ', ' in test:
test1 = comma_and_space(test)
test1 = json.dumps(test1)
print(test1)
else:
print("didn't hit any of those")
print(len(test1))
print(test1)
for item in testing_accounts:
for email in test1:
item.update({'email': email})
#temp = json.loads(testing_accounts)
#temp.update({'email': test})
print(item)
any guidance would be greatly appreciated.