#!/usr/bin/python
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
import cgi
import os
import time
import glob
import re
import ConfigParser
configuration = ConfigParser.ConfigParser()
configuration.read('configuration')
blog_title = configuration.get('personal', 'blog_title')
keywords = configuration.get('personal', 'keywords')
entries_dir = configuration.get('personal', 'entries_dir')
entries_suffix = configuration.get('personal', 'entries_suffix')
staticpages_dir = configuration.get('personal', 'staticpages_dir')
style = configuration.get('look', 'style')
entries_per_page = configuration.getint('look', 'entries_per_page')
monthlist = configuration.get('look', 'monthlist')
staticpages = configuration.get('look', 'staticpages')
permalinks = configuration.get('look', 'permalinks')
newest_first = configuration.get('look', 'newest_first')
action = cgi.FieldStorage()
month_display = action.getvalue('m')
post_display = action.getvalue('p')
static_display = action.getvalue('s')
site_display = action.getvalue('i')
if not month_display: month_display = ""
if not post_display: post_display = ""
if not static_display: static_display = ""
if not site_display: site_display = ""
print 'Content-type: text/html\n'
print ''
print ''
print '
'
print ' '
if static_display != "": # Show Staticpage
content = open(staticpages_dir + static_display, "r")
print '
' + re.sub('\d+?-', '', static_display) + '
'
print '
'
for line in content:
print ' ' + line.strip() + '
'
print '
'
content.close()
else: # Show regular entry
entry_counter = 0
for entry in entries:
date = time.strftime("%c", entry[0])
date_to_compare = time.strftime("%m%Y", entry[0]) # Needed for permalinks
entry = entry[1]
title = entry.replace('entries/', '', 1)
title = title.replace('.txt', '')
entry_counter += 1
if month_display == date_to_compare or not month_display:
if post_display == title or not post_display:
if entry_counter <= entries_per_page:
content = open(entry, "r")
if permalinks:
print '
'
else:
print '
' + title + ' (' + date + ')
'
print '
'
for line in content:
print ' ' + line.strip() + '
'
print '
'
print '
'
content.close()
if entry_counter > entries_per_page: # Display pagelist
print '
'
print '
'
print ' '
print ''
# vim: set tw=0 ts=4: