Skip to content

Instantly share code, notes, and snippets.

@swinton
Created February 28, 2011 14:37
Show Gist options
  • Select an option

  • Save swinton/847395 to your computer and use it in GitHub Desktop.

Select an option

Save swinton/847395 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import csv
from sqlalchemy import *
def csv_to_mysql(filename="data-no-blanks.csv"):
# Prepare db connection (SQLAlchemy stuff)
db = create_engine("mysql://root:root@localhost/datacopter_thepromise")
metadata = MetaData(db)
t = Table("datacopter_tweettotal_by_minute", metadata, autoload=True)
# Read in the data
f = csv.reader(open(filename))
# Discard headers
f.next()
# Insert the data
i = t.insert()
for line in f:
minute, total = map(int, line)
i.execute(minute=minute, total=total)
if __name__ == "__main__":
csv_to_mysql()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment