Esempio n. 1
0
def csv_to_db(csvFile=None):
	"""Generate db rows from csv input."""	
	with open(csvFile, 'rb') as f:
		csvReader = csv.reader(f)
		for row in csvReader:
			yield COL_DELIMITER.join(row)
Esempio n. 2
0
# 	"""
# 	def __call__(self, key, value):
# 		u, v = key, value.upper()
# 		yield u, v
		
		
if __name__ == "__main__":
	if DEBUG:
		users = []
		usersCols = [
			"{userId}",
			"{firstName}",
			"{lastName}",
			"{dob}"
		]
		rowTemplate = COL_DELIMITER.join(usersCols)
		users.append(rowTemplate.format(userId=1001, firstName="Paul", lastName="Dirac", dob="1902-10-20 00:00:00"))
		users.append(rowTemplate.format(userId=1002, firstName="Albert", lastName="Einstein", dob="1955-04-18 00:00:0"))
		users.append(rowTemplate.format(userId=1003, firstName="Richard", lastName="Feynman", dob="1918-05-11 00:00:0"))
		users.append(rowTemplate.format(userId=1004, firstName="Erwin", lastName="Schrodinger", dob="1887-08-12 00:00:0"))
		source = StringIO.StringIO(ROW_DELIMITER.join(users) + ROW_DELIMITER)
	else:
		source = sys.stdin
		
	argsDict = {}
	dynamicMapper = None
	if len(sys.argv) > 1:
		try:
			if hasattr(globals()[sys.argv[1]], '__call__'):
				dynamicMapper = globals()[sys.argv[1]]
				className = sys.argv.pop(1)