def exportcsv(dataType): c = setting() l = logger('exportData') databasePath = c.get('parser', 'db_path') db = dbConnection(databasePath, l) try: filename = c.get('exportcsv', 'output_path') + '/export-data-' + dataType + '.csv' file = open(filename, "w") writer = csv.writer(file, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL) data = [] if 'station' == dataType: headers = db.getAllStationInfoHeaders() data = db.getAllStationInfo() elif 'train' == dataType: headers = db.getAllTrainInfoHeaders() data = db.getAllTrainInfo() # Writing the values writer.writerow(list(headers)) for row in data: writer.writerow(list(row)) file.close() except (IOError, Exception) as e: print e
def exportcsv(dataType): c = setting() l = logger('exportData') databasePath = c.get('parser', 'db_path') db = dbConnection(databasePath, l) try: filename= c.get ('exportcsv', 'output_path') + '/export-data-' + dataType + '.csv' file = open(filename, "w") writer = csv.writer(file, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL) data = [] if 'station' == dataType: headers = db.getAllStationInfoHeaders() data = db.getAllStationInfo() elif 'train' == dataType: headers = db.getAllTrainInfoHeaders() data = db.getAllTrainInfo() # Writing the values writer.writerow(list(headers)) for row in data: writer.writerow(list(row)) file.close() except (IOError, Exception) as e: print e
def __init__(self, databasePath, systemType): self.systemType = systemType self.logging = logger(self.systemType) self.databasePath = databasePath self.db = dbConnection(self.databasePath, self.logging) self.writer = publish(self.logging) self.__cfg = setting() self.__ticketPrint = False
def __init__(self): self.c = setting() self.logging = logger('export') databasePath = self.c.get('parser', 'db_path') self.db = dbConnection(databasePath, self.logging) self.writeCsv() dataClean = int(self.c.get('exportcsv', 'data_clean')) if 1 == int(dataClean): self.db.deleteAllTicketDetails()
def importcsv(dataType): c = setting() l = logger('exportData') databasePath = c.get('parser', 'db_path') db = dbConnection(databasePath, l) try: filename = c.get('exportcsv', 'output_path') + '/import-data-' + dataType + '.csv' reader = csv.reader(open(filename, 'r'), delimiter=',') if 'station' == dataType: tablename = 'stationinfo' elif 'train' == dataType: tablename = 'traininfo' rowno = 1 fields = '' for data in reader: if 1 == rowno: # Validating colums validColumns(dataType, data) # Drop the schema of table try: db.cursor.execute('drop table ' + tablename) except Exception as e: pass # create the table sql = createTable(tablename, data) db.cursor.execute(sql) # build the insert query sql = insertTable(tablename, data) else: # execute the insert query try: db.cursor.execute(sql, data) db.connection.commit() except (IOError, Exception) as e: print 'Error: Inserting row :' + e rowno += 1 #db.connection.commit() except (IOError, Exception) as e: print e
def importcsv(dataType): c = setting() l = logger('exportData') databasePath = c.get('parser', 'db_path') db = dbConnection(databasePath, l) try: filename= c.get ('exportcsv', 'output_path') + '/import-data-' + dataType + '.csv' reader = csv.reader(open(filename, 'r'), delimiter=',') if 'station' == dataType: tablename = 'stationinfo' elif 'train' == dataType: tablename = 'traininfo' rowno = 1 fields = '' for data in reader: if 1 == rowno: # Validating colums validColumns(dataType, data) # Drop the schema of table try: db.cursor.execute('drop table ' + tablename) except Exception as e: pass # create the table sql = createTable(tablename, data) db.cursor.execute(sql) # build the insert query sql = insertTable(tablename, data) else: # execute the insert query try: db.cursor.execute(sql, data) db.connection.commit() except (IOError, Exception) as e: print 'Error: Inserting row :' + e rowno += 1 #db.connection.commit() except (IOError, Exception) as e: print e