My current script saves to an excel file but i would like to directly upload it to my mysql database.
for i in range(0, len(names)):
ws.append([names[i], str((float(sells[i])+float(buys[i]))/2.0)])
except:
print('Cannot fetch from this link')
print('Saving the file with name markets.xlsx')
wb.save("markets.xlsx")
how would i perform a loop to do the following
sql = "INSERT INTO todaysmarkets(Name,value) VALUES(%s,%s)"
****Update*****
following the advice on here i now have the following:
cnx = mysql.connector.connect(host='.com', user='', password='', database='')
cursor = cnx.cursor()
for i in range(0, len(names)):
cursor.execute(("INSERT INTO todaysmarkets(Name,value) VALUES(%s,%s)"), (names[i], str((float(sells[i])+float(buys[i]))/2.0)))
cnx.close()
script runs through with no errors but the database is not updated.
mysqlwithout user/password/database selected? I would guess you need these setup first (usemysqlconsole command, connect to mysql, create database, create user with password and grant user rights to connect to127.0.0.1or tolocalhost). You will also need your tabletodaymarketscreated with columnsNameandvalue. You will then need to update your connection string (`mysql.connector.connect(host='127.0.0.1', user='your_user', password='your_password', database='your_database')