have the following code. It is very easy to execute, only my problem is, I get it entered 11 times at once. So when I execute this code it copies the content 11 times into the database.
row 1
row 2
row 3
...
row 11
This is what I try to output :
{
'note': '',
'money': 76682.1200000005,
'main': True,
'deleted': False,
'_id': '5e3e2bc4667b8d5fc053e9a1',
'ownerCharacter':
{
'_id': '5e3ddb08667b8d5fc052903d',
'name': 'Name'
},
'bank':
{
'_id': '5b36b968614626df322e5b75',
'imageUrl': 'urlToIMG',
'name': 'Savings Bank Paleto Bay'
},
'bankAccountType':
{
'type': 'private',
'title': '',
'interestRate': 0.01,
'_id': '5b36b968614626df322e5b76',
'name': 'Giro-Konto',
'bank': '5b36b968614626df322e5b75',
'__v': 0
},
'vban': '460907',
'pin': '1234',
'__v': 0
}
And this is the code:
def getData():
databaseConn = dbConnect()
cursor = databaseConn.cursor()
delete = "TRUNCATE TABLE bank"
try:
cursor.execute(delete)
databaseConn.commit()
except:
print("Delete error")
money = json.loads(makeRequest("URL", authToken, True).text)
for amount in money:
geld = str(money["money"])
person = money["ownerCharacter"]["name"]
sql = "INSERT INTO bank (menge,name) VALUES (%s,%s)"
val = (geld,person)
try:
cursor.execute(sql, val)
databaseConn.commit()
except:
print("Error Database")
dbClose(databaseConn, cursor)
I just need it once the output not 11 times in a row. What am I doing wrong?