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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.