Skip to content
Browse files

Add basic scripts demonstrating database access using sqlite Python b…

…indings.
  • Loading branch information...
1 parent 7bd4948 commit 8a46dbaec6e840fe8d492c77631a9d44308f2998 @jesstess committed Jul 26, 2012
Showing with 51 additions and 0 deletions.
  1. +13 −0 jeopardy_categories.py
  2. +17 −0 jeopardy_clues.py
  3. +21 −0 jeopardy_mythology_clues.py
View
13 jeopardy_categories.py
@@ -0,0 +1,13 @@
+from pysqlite2 import dbapi2 as sqlite
+
+connection = sqlite.connect('jeopardy.db')
+cursor = connection.cursor()
+
+cursor.execute("SELECT name FROM category LIMIT 10")
+results = cursor.fetchall()
+
+print "Example categories:\n"
+for category in results:
+ print category[0]
+
+connection.close()
View
17 jeopardy_clues.py
@@ -0,0 +1,17 @@
+from pysqlite2 import dbapi2 as sqlite
+
+connection = sqlite.connect('jeopardy.db')
+cursor = connection.cursor()
+
+cursor.execute("SELECT text, answer, value FROM clue LIMIT 10")
+results = cursor.fetchall()
+
+print "\nExample clues:\n"
+for clue in results:
+ text, answer, value = clue
+ print "[$%s]" % (value,)
+ print "A: %s" % (text,)
+ print "Q: What is '%s'" % (answer,)
+ print ""
+
+connection.close()
View
21 jeopardy_mythology_clues.py
@@ -0,0 +1,21 @@
+from pysqlite2 import dbapi2 as sqlite
+
+connection = sqlite.connect('jeopardy.db')
+cursor = connection.cursor()
+
+query = """SELECT category.name, clue.text, clue.answer
+FROM clue, category WHERE clue.category=category.id
+AND category.name LIKE '%MYTHOLOGY%' LIMIT 10"""
+
+cursor.execute(query)
+results = cursor.fetchall()
+
+print "\nExample MYTHOLOGY clues:\n"
+for clue in results:
+ name, text, answer = clue
+ print "In the category of %s" % (name,)
+ print "A: %s" % (text,)
+ print "Q: What is '%s'" % (answer,)
+ print ""
+
+connection.close()

0 comments on commit 8a46dba

Please sign in to comment.
Something went wrong with that request. Please try again.