Skip to content

Instantly share code, notes, and snippets.

@Busata
Created December 8, 2014 09:20
Show Gist options
  • Save Busata/465a0bd4fcf3493d0aa4 to your computer and use it in GitHub Desktop.
Save Busata/465a0bd4fcf3493d0aa4 to your computer and use it in GitHub Desktop.
def run_import():
with open('listings.csv', 'r') as csv_file:
reader = csv.reader(csv_file, delimiter=";")
inserts = []
for row in reader:
inserts.append({'item_id': int(row[0]),
'order_type': ItemOrderType.from_string(row[1].replace('<','').replace('>','')),
'listings': int(row[2]),
'unit_price': int(row[3]),
'quantity': int(row[4])})
if len(inserts) == 10000:
db.engine.execute(ItemOrder.__table__.insert(), inserts)
inserts = []
db.engine.execute(ItemOrder.__table__.insert(), inserts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment