Created
June 10, 2014 16:57
-
-
Save pbojinov/ee67ab04d5d3cea86fd6 to your computer and use it in GitHub Desktop.
Create and populate a sqlite database using python sqlite3 adapter
This file contains 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
# first create a databse, from the command line run | |
# > touch hello_world.db | |
from datetime import datetime, timedelta | |
import sqlite3 | |
conn = sqlite3.connect('hello_world.db') | |
c = conn.cursor() | |
# Create table | |
c.execute(''' | |
CREATE TABLE tlds | |
(tld text, tag text, vertical text, brand text, cc text, url text)''') | |
# sample dummy data | |
tld = 'abcdefghijkk' | |
tag = 'abcdefghijk' | |
vertical = 'abcdefghijk' | |
brand = 'abcdefghijk' | |
cc = 'us' | |
url = 'abcdefghijklmnobqrstuvwxyz1234567890' | |
query = "INSERT INTO tlds VALUES ('%s','%s','%s','%s','%s','%s')" % (tld, tag, vertical, brand, cc, url) | |
print query # to make sure we have the right thing | |
# do 2 million entries | |
for i in range(0,2000000): | |
# Insert a row of data | |
c.execute(query) | |
print 'insert # %d' % i | |
# Save (commit) the changes | |
conn.commit() | |
# We can also close the connection if we are done with it. | |
# Just be sure any changes have been committed or they will be lost. | |
conn.close() | |
print 'done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment