I’m currently uploading data to a table using the following script, I need to modify the script so it writes the same data to an additional table. I’ve this myself a few times but I can only get it to write to one or the other, never both.
Any suggestions?
[code]def getMonthNum(month):
months = [“JAN”, “FEB”, “MAR”, “APR”, “MAY”, “JUN”, “JUL”, “AUG”, “SEP”, “OCT”, “NOV”, “DEC”]
monthsNum = [“01”, “02”, “03”, “04”, “05”, “06”, “07”, “08”, “09”, “10”, “11”, “12”]
index = months.index(month.upper())
return monthsNum[index]
path = fpmi.file.openFile(“csv”)
if path != None:
fpmi.db.runUpdateQuery(“delete from vendorforcast”, “manufacturing”)
file = open(path, ‘r’)
i = 1
dates = []
for line in file.readlines():
data = line.split(",")
if data[1].strip() == "":
break
if i == 1:
for x in range(3, len(data)):
dateArray = data[x].split("-")
dateStr = "20%s-%s-%s 00:00:00" % (dateArray[2].replace("\n", ""), getMonthNum(dateArray[1].replace("\n", "")), dateArray[0].replace("\n", ""))
dates.append(dateStr)
elif i >= 2:
y = 3
for date in dates:
vfID = fpmi.db.runScalarQuery("SELECT ID FROM vendorforcast WHERE BL_Number = '%s' AND TStamp = '%s'" % (data[2].strip(), date), "manufacturing")
if vfID == None:
query = "INSERT INTO VendorForcast (Part, BL_Number, TStamp, BL_Value) VALUES (%s, '%s', '%s', %s)" % (data[1].strip(), data[2].strip(), date, data[y].replace("\n", ""))
else:
query = "UPDATE VendorForcast SET BL_Value = %s WHERE ID = %s" % (data[y].replace("\n", ""), vfID)
fpmi.db.runUpdateQuery(query, "manufacturing")
y = y + 1
i = i + 1[/code]