コード例 #1
0
 def testNoTimezoneChange(self):
     self.assertEqual(utl.reformatDate('12-Mar-10','12:00:00','UTC'),'2010-03-12 12:00')
コード例 #2
0
 def testTimezoneChange(self):
     self.assertEqual(utl.reformatDate('12-Mar-10','12:00:00','America/Guyana'),'2010-03-12 16:00')
コード例 #3
0
        sys.exit("Exiting ... File %s not found" % filename)
        
#    connect to database
    conn = utl.connectMysql(args.dbase)
    csr = conn.cursor()

#    read csv file of prices and convert to list
#    INSERT prices into value table using a loop
    with open(filename, 'rU') as f:
        try:
            reader = csv.DictReader(f,fieldnames=('Ticker','Session','Date','Price'))
            numInserted= 0
            for row in reader:
                if (reader.line_num > 1):
                    if ((row['Price'].find('N/A') == -1) and (len(row['Price'])>0)):
                        hhmmss = str( asst[(exID,row['Ticker'])][1] )
                        tzon = asst[(exID,row['Ticker'])][2]
                        sqlStmt= "insert into value (assetID, datetime, valueTypeID, value) values (%d, '%s', 1, %s)" % (asst[(exID,row['Ticker'])][0], utl.reformatDate(row['Date'],hhmmss,tzon), row['Price'])
                        print sqlStmt
                        csr.execute(sqlStmt)
                        numInserted += 1
#            print "Number of rows: %d" % (reader.line_num-1)
        except Exception, e:
            sys.exit('Exiting from data insertion...File %s, line %d, %s' % (filename, reader.line_num, e))
        finally:
            csr.close()
            conn.commit()
            print "Number of rows added: %d" % (numInserted)
            f.close()