basic sql2csv

This commit is contained in:
Michael Herman 2015-02-16 22:58:11 -07:00
parent 0523b16f80
commit 25e5b3a8d0
2 changed files with 19 additions and 1 deletions

17
24_sql2csv.py Normal file
View File

@ -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()

View File

@ -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.
1. **23_flask_session_test.py**: Just a simple app to see if the sessions are working
1. **24_sql2csv.py**: SQL to CSV.