[Swift-commit] r2644 - SwiftApps/SIDGrid/swift/projects/andric/peakfit_pilots/PK2/PK2surfaces/surfaceData

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Fri Mar 6 01:23:21 CST 2009


Author: andric
Date: 2009-03-06 01:23:20 -0600 (Fri, 06 Mar 2009)
New Revision: 2644

Added:
   SwiftApps/SIDGrid/swift/projects/andric/peakfit_pilots/PK2/PK2surfaces/surfaceData/insertData.py
Log:
Python script using MySQLdb module to insert data into MySQL tables

Added: SwiftApps/SIDGrid/swift/projects/andric/peakfit_pilots/PK2/PK2surfaces/surfaceData/insertData.py
===================================================================
--- SwiftApps/SIDGrid/swift/projects/andric/peakfit_pilots/PK2/PK2surfaces/surfaceData/insertData.py	                        (rev 0)
+++ SwiftApps/SIDGrid/swift/projects/andric/peakfit_pilots/PK2/PK2surfaces/surfaceData/insertData.py	2009-03-06 07:23:20 UTC (rev 2644)
@@ -0,0 +1,35 @@
+#!/usr/bin/python
+
+import commands
+import os
+import sys
+import MySQLdb
+import time
+
+
+hemis = ['lh','rh']
+
+try:
+    connection = MySQLdb.connect(read_default_file="~/.my.cnf",db="HEL")
+except MySQLdb.Error, e:
+    print "Error %d: %s" % (e.args[0], e.args[1])
+    sys.exit (1)
+    
+cursor = connection.cursor()
+
+def insertdata_to_db(h):
+    print "que hora es?\n"+time.ctime()
+    try:
+        file = "'/disks/ci-gpfs/fmri/cnari/swift/projects/andric/peakfit_pilots/PK2/PK2surfaces/surfaceData/PK2_"+h+"_fordb.txt'"
+        print "File loading: "+file
+        insert_statement = "load data local infile "+file+" into table peakFunc_data"+h+" fields terminated by ' ';"
+        print "Insert statement: "+insert_statement
+        cursor.execute(insert_statement)
+        print "Number of rows inserted: %d" % cursor.rowcount
+    except MySQLdb.Error, e:
+        print "Error loading peakFunc_data"+h+"  %d -->> %s" % (e.args[0], e.args[1])
+        sys.exit (1)
+
+
+for h in hemis:
+    insertdata_to_db(h)




More information about the Swift-commit mailing list