import os, sys def create(): import sqlite3 import dbconfig c = dbconfig.connection.cursor() print c.executescript("""CREATE TABLE notes ( id INTEGER PRIMARY KEY autoincrement, note TEXT, rev INTEGER DEFAULT 0); CREATE TRIGGER insert_notes_revision AFTER UPDATE ON notes BEGIN UPDATE notes SET rev = rev+1 WHERE id = new.id; END; INSERT INTO notes (note) VALUES ("testing"); INSERT INTO notes (note) VALUES ("testing2"); INSERT INTO notes (note) VALUES ("testing3"); INSERT INTO notes (note) VALUES ("testing4"); INSERT INTO notes (note) VALUES ("testing5"); """) c.execute("select id, note, rev from notes where id=?;", (1,)) for row in c: print row def run(): import urls if os.environ.get("REQUEST_METHOD", ""): from wsgiref.handlers import BaseCGIHandler f = file("log.txt", "w") BaseCGIHandler(sys.stdin, sys.stdout, f, os.environ).run(urls.urls) f.close() else: from wsgiref.simple_server import WSGIServer, WSGIRequestHandler httpd = WSGIServer(('', 8080), WSGIRequestHandler) httpd.set_app(urls.urls) print "Serving HTTP on %s port %s ..." % httpd.socket.getsockname() httpd.serve_forever() if __name__ == "__main__": if 'create' in sys.argv: create() if 'run' in sys.argv: run()