From 8fc01d24ee3fdcb9ba22ca5506f053fa2e5708b7 Mon Sep 17 00:00:00 2001 From: Stefan Krulj Date: Thu, 15 Mar 2012 20:48:15 +0100 Subject: [PATCH] RSS feed added and validated by the W3C validator, shows some issues with todays dates, looks good to me must ask someone --- pylog.py | 59 +++++++++++++++++++++++++++++++++++++++++++++---- pylog_config.py | 2 ++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/pylog.py b/pylog.py index 1d2d749..c1de35d 100755 --- a/pylog.py +++ b/pylog.py @@ -1,7 +1,7 @@ #!/usr/bin/python import os,os.path, sys -import urllib, cgi +import urllib, cgi,time import cgitb cgitb.enable() @@ -12,7 +12,7 @@ from datetime import datetime from pylog_action import * import pylog_config as cfg - +__version = "v0.1-(2012-03-15)" def header(): @@ -162,8 +162,59 @@ def get_valid_path(path): return cfg.contentdir return os.path.normpath(path) - -print 'Content-type: text/html\n\n' +if not 'rss' in form: + sys.stdout.write('Content-type: text/html\n\n') +else: + import xml.etree.ElementTree as ET + sys.stdout.write('Content-type: text/xml\n\n') + + script = sys.argv[0][sys.argv[0].rindex('/')+1:] + files,keys=get_newest(cfg.numofposts) + tz = str(time.timezone) + + print ''' + + + ' + + print " "+cfg.blogtitle+"" + print " "+cfg.subtitle+"" + print " "+cfg.topurl+script+"" + print " Pylog"+__version+"" + if len(keys)>0: + date=datetime.fromtimestamp(int(keys[0])).strftime("%a, %d %b %Y %H:%M:%S ") + print " "+date+tz+"" + + for k in keys: + date=datetime.fromtimestamp(int(k)).strftime("%a, %d %b %Y %H:%M:%S ") + for f in files[k]: + if '.' in os.path.basename(f): + typ = f[f.rindex('.')+1:] + name = os.path.basename(f)[:-(len(typ)+1)] + else: + typ = '' + name = os.path.basename(f) + + + print " " + print " "+name+"" + + link = ET.Element("link") + link.text = cfg.topurl+script+'?'+urllib.urlencode({'path': os.path.normpath(os.path.dirname(f)),'disp':os.path.normpath(f)}) + print " ", + ET.dump(link) + link.tag="guid" + print " ", + ET.dump(link) + + print " "+date+tz+"" + print " " + + print "" + print "" + + sys.exit(0) + path = cfg.contentdir diff --git a/pylog_config.py b/pylog_config.py index df6e400..13f16e7 100644 --- a/pylog_config.py +++ b/pylog_config.py @@ -10,3 +10,5 @@ datefmt='%Y-%m-%d' contentdir="cnt" numofposts=5 #number of previews on the base site numfeed=5 #number of previews in the feed + +topurl="http://n0g.at/~powertomato/pylog/"