Created
February 28, 2011 14:37
-
-
Save swinton/847395 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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