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.
24 conn
= sqlite3
.connect(config
.DBPATH
)
25 conn
.execute("CREATE TABLE IF NOT EXISTS entries (id INTEGER PRIMARY KEY, date , title TEXT, text TEXT)")
26 except sqlite3
.OperationalError
:
27 print 'Failed to connect to database. Check file and directory permissions.'
31 def getnumposts(conn
, id=None):
32 """Enumerate the number of posts in the database. if an ID is specified
33 then enumerate the number of posts with that ID. The latter should be 0 or
34 1 so essentially this is a check for whether the specified post exists.
37 numposts
= conn
.execute("SELECT count(id) FROM entries WHERE id = ?", (id,)).fetchone()
39 numposts
= conn
.execute("SELECT count(id) FROM entries").fetchone()
40 return int(numposts
[0])
42 def printheaders(title
):
44 print '<title>' + title
+ '</title>'
45 print '<link href="default.css" rel="stylesheet" type="text/css">'
48 def displaypost(title
, body
, date
=None):
49 """Formats and prints a post"""
50 print '<div class="blogpost">'
51 print '<h1>%s</h1>' % title
53 print '<h3>%s</h3>' % date
54 print markdown2
.markdown(body
)