something like this would put a csv file into a db table. pymsql is pure python.
# csv to MySQL
import os, shutil, csv, pymysql
inputPath = '/path/to/input/folder/'
archivePath = '/path/to/archive/folder'
# get list of files
files = os.listdir(inputPath)
if len(files) > 0:
# set MySQL connection
connection = pymysql.connect(host='host.com', user='', password='', db='', cursorclass=pymysql.cursors.DictCursor)
# set query
query = 'INSERT INTO table VALUES(%s, %s, %s, %s, %s)'
# loop through files
for file in files:
inputFile = inputPath + file
# open csv file
dataIn = csv.reader(inputFile, delimiter =',' quotechar ='"')
# write to db
with connection.cursor() as cursor:
for line in dataIn:
cursor.execute(sql, (line[0]))
# commit and close the MySQL connection
connection.commit()
connection.close()
# move the files to the archive folder
for file in files:
shutil.move(inputPath + file, archivePath + file)
As far as putting it into the Ignition historian without using Ignition, I can’t help you there, because I don’t use the historian. None of the applications I have here have any need of it.