1 # Copyright (c) 2008, 2009, Simon Morgan <sjm@spamcop.net>
3 # Permission to use, copy, modify, and/or distribute this software for any
4 # purpose with or without fee is hereby granted, provided that the above
5 # copyright notice and this permission notice appear in all copies.
7 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 conn
= sqlite3
.connect(config
.DBPATH
)
23 conn
.execute("CREATE TABLE IF NOT EXISTS entries (id INTEGER PRIMARY KEY, date , title TEXT, text TEXT)")
24 except sqlite3
.OperationalError
:
25 print 'Failed to connect to database. Check file and directory permissions.'
29 def getnumposts(conn
, id=None):
30 """Enumerate the number of posts in the database. if an ID is specified
31 then enumerate the number of posts with that ID. The latter should be 0 or
32 1 so essentially this is a check for whether the specified post exists.
35 numposts
= conn
.execute("SELECT count(id) FROM entries WHERE id = ?", (id,)).fetchone()
37 numposts
= conn
.execute("SELECT count(id) FROM entries").fetchone()
38 return int(numposts
[0])
40 def printheaders(title
):
42 print '<title>' + title
+ '</title>'
43 print '<link href="default.css" rel="stylesheet" type="text/css">'