Skip to content

Instantly share code, notes, and snippets.

@dguzzo
Last active June 13, 2016 00:44
Show Gist options
  • Save dguzzo/6afe6c83fc83ddc4f66904b3d96a362c to your computer and use it in GitHub Desktop.
Save dguzzo/6afe6c83fc83ddc4f66904b3d96a362c to your computer and use it in GitHub Desktop.
put some colors from colourlovers.com into a sqlite database
#!/Library/Frameworks/Python.framework/Versions/3.4/bin/python3
# -*- coding: utf-8 -*-
import sqlite3 as lite
from colourlovers import ColourLovers
def getColors():
cl = ColourLovers()
colors = cl.colors()
return tuple([(color.title, color.hex) for color in colors])
colors_tuple = getColors()
con = lite.connect('colors.db')
with con:
cur = con.cursor()
cur.execute("DROP TABLE IF EXISTS Colors")
cur.execute("CREATE TABLE Colors(Id INTEGER PRIMARY KEY, Title TEXT, Hex TEXT UNIQUE)")
cur.executemany("INSERT INTO Colors(Title, Hex) VALUES(?, ?)", colors_tuple)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment