Jump to content

tab separated text files into mysql with extra . . .


2tonejoe

Recommended Posts

ok. I wrote a python script to import multiple tab separated text files into a mySQL database. The code is fine, however the module I was using is broken in the version of python I have to use. I can't upgrade so I am searching out other methods of getting this information into the database. . . . along came php.

 

I need to essentially read a list of files, for each file assign variables based on the file name, read in each row and assign variables for each field, then REPLACE that data in the dbase if it exists. I am including my python function to help you guys understand what I am saying:

 

def txtImport(file):
os.chdir(readyDir)
tempTuple = os.path.splitext(file)
stringName = tempTuple[0]
bkName = stringName[0:3]
bkYear = stringName[3:7]
bkIssue = stringName[7:9]
bkType = stringName[9:11]
bkVersion = stringName[11:15]
bkYear2 = int(bkYear)
bkIssue2 = int(bkIssue)
reader = csv.reader(open(file, "rb"), delimiter='\t', quoting=csv.QUOTE_NONE)
for row in reader:
	ioBar = row[0]
	name = row[1]
	page = row[2]
	size = row[3]
	color = row[4]
	category = row[5]
	website = row[6]
	salesRep = row[7]
	account = row[8]
	layout = row[9]

 

I am thinking if I can figure out how to do this I will just cron a wget to the page and to process the list of files.

 

Anyone have any advice or code examples?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.