Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- #-*- coding: utf-8 -*-
- import csv
- import optparse
- template = """INSERT INTO [spacebottle].[Detail] (name, owner, operator, users, purpose, orbit_class, orbit_type, launch_mass, dry_mass, power, launch_date, lifetime, contractor, contractor_country, launch_site, launch_vehicle, cospar, norad,comment) VALUES({});"""
- def main():
- parser = optparse.OptionParser()
- opts, args = parser.parse_args()
- filename = args[0]
- def safe_word(word):
- if "'" in word:
- word = word.replace("'", "''")
- return "'{}'".format(word)
- with open(filename, 'rb') as fp:
- reader = csv.reader(fp)
- for ii, rows in enumerate(zip(*[iter(reader)]*150)):
- with open('test.{}.txt'.format(ii), 'w+b') as bp:
- for row in rows:
- row = row[:19]
- row = map(safe_word, row)
- line = ','.join(row)
- line = template.format(line) + '\n'
- bp.write(line)
- #print template.format(line) # outout to stdout
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement