2tonejoe Posted December 10, 2007 Share Posted December 10, 2007 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? Quote Link to comment Share on other sites More sharing options...
2tonejoe Posted December 11, 2007 Author Share Posted December 11, 2007 bump Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 11, 2007 Share Posted December 11, 2007 go to php.net read up on the functions file_get_contents explode mysql_query and then ask a question Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.