From 25e5b3a8d0a4cf75cbf48f5bf54ae2f18832b38a Mon Sep 17 00:00:00 2001 From: Michael Herman Date: Mon, 16 Feb 2015 22:58:11 -0700 Subject: [PATCH] basic sql2csv --- 24_sql2csv.py | 17 +++++++++++++++++ readme.md | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 24_sql2csv.py diff --git a/24_sql2csv.py b/24_sql2csv.py new file mode 100644 index 0000000..19d0c42 --- /dev/null +++ b/24_sql2csv.py @@ -0,0 +1,17 @@ +import sys +import csv +import sqlite3 + +if len(sys.argv) < 3: + print "Use: {0} DATABASE_NAME TABLE_NAME".format(sys.argv[0]) + exit() + +conn = sqlite3.connect(sys.argv[1]) +cur = conn.cursor() +data = cur.execute("SELECT * FROM {0}".format(sys.argv[2])) + +with open('output.csv', 'wb') as f: + writer = csv.writer(f) + writer.writerows(data) + +conn.close() diff --git a/readme.md b/readme.md index 2e3022d..33caedd 100644 --- a/readme.md +++ b/readme.md @@ -22,4 +22,5 @@ 1. **20_restore_file_from_git.py**: Restore file from Git History 1. **21_twitter_bot.py**: Twitter Bot 1. **22_git_tag.py**: Create Git Tag based on a commit -1. **23_flask_session_test.py**: Just a simple app to see if the sessions are working. \ No newline at end of file +1. **23_flask_session_test.py**: Just a simple app to see if the sessions are working +1. **24_sql2csv.py**: SQL to CSV. \ No newline at end of file