Skip to content

Instantly share code, notes, and snippets.

@Motoma
Created September 21, 2010 15:17
Show Gist options
  • Save Motoma/589837 to your computer and use it in GitHub Desktop.
Save Motoma/589837 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
# dsimport.py
import sys
from CSVFileHandler import CSVFileHandler
def main(ifile, ofile):
writer = open(ofile, 'w')
def processFile(line, args):
query = """INSERT INTO `trans` (`trans_code_id`, `generic_descriptor`, `amount`,
`personal_information`, `related_id`, `created`, `last_modified`)
(SELECT %s, '%s', %s, '%s', c.client_id, '%s', '%s' FROM client c WHERE
c.username = '%s');""" % (line[1], line[0], line[14], line[14], line[3], line[32],
line[4])
print>>writer, query
handler = CSVFileHandler(ifile)
handler.process(processFile, ())
def usage():
print "dsimport.py <csv filename> <sql output filename>\n"
if __name__ == "__main__":
if len(sys.argv) == 3:
main(sys.argv[1], sys.argv[2])
else:
usage()
sys.exit(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment