I have the following code that parses data from an XML file.
import MySQLdb
from xml.dom import minidom
xmldoc = minidom.parse("report.xml")
parking_report = xmldoc.getElementsByTagName("parking_report")[0]
sensors = parking_report.getElementsByTagName("sensor")
for sensor in sensors:
id = sensor.getElementsByTagName("id")[0].firstChild.data
date = sensor.getElementsByTagName("date")[0].firstChild.data
time = sensor.getElementsByTagName("time")[0].firstChild.data
status = sensor.getElementsByTagName("status")[0].firstChild.data
db = MySQLdb.connect(host="localhost",user="root",passwd="pass",db="parking_report")
cur = db.cursor()
cur.execute('INSERT INTO report_table (id, date, time, status) VALUES (id, date, time, status)')
print(id, date, time, status)
Right now, it runs without errors and returns the id, date, time and status of each parking sensor. However, my mySQL table (parking_report) also has the columns ID, Date, Time and Status. I want to insert the data of those variables into my table under those columns. (Note there are three separate sensors so I will need three rows of data in the end.)
When I run this it does not insert into my table. Please Help! Thank you.