RSS feed added and validated by the W3C validator, shows some issues with todays dates, looks good to me must ask someone

master
Stefan Krulj 15 years ago
parent c0de1e77a8
commit 8fc01d24ee
  1. 57
      pylog.py
  2. 2
      pylog_config.py

@ -1,7 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
import os,os.path, sys import os,os.path, sys
import urllib, cgi import urllib, cgi,time
import cgitb import cgitb
cgitb.enable() cgitb.enable()
@ -12,7 +12,7 @@ from datetime import datetime
from pylog_action import * from pylog_action import *
import pylog_config as cfg import pylog_config as cfg
__version = "v0.1-(2012-03-15)"
def header(): def header():
@ -162,8 +162,59 @@ def get_valid_path(path):
return cfg.contentdir return cfg.contentdir
return os.path.normpath(path) return os.path.normpath(path)
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 '''<?xml version="1.0"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="'''+cfg.topurl+script+'?rss=1'+'" rel="self" type="application/rss+xml" />'
print " <title>"+cfg.blogtitle+"</title>"
print " <description>"+cfg.subtitle+"</description>"
print " <link>"+cfg.topurl+script+"</link>"
print " <generator>Pylog"+__version+"</generator>"
if len(keys)>0:
date=datetime.fromtimestamp(int(keys[0])).strftime("%a, %d %b %Y %H:%M:%S ")
print " <lastBuildDate>"+date+tz+"</lastBuildDate>"
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 " <item>"
print " <title>"+name+"</title>"
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 " <pubDate>"+date+tz+"</pubDate>"
print " </item>"
print "</channel>"
print "</rss>"
sys.exit(0)
print 'Content-type: text/html\n\n'
path = cfg.contentdir path = cfg.contentdir

@ -10,3 +10,5 @@ datefmt='%Y-%m-%d'
contentdir="cnt" contentdir="cnt"
numofposts=5 #number of previews on the base site numofposts=5 #number of previews on the base site
numfeed=5 #number of previews in the feed numfeed=5 #number of previews in the feed
topurl="http://n0g.at/~powertomato/pylog/"

Loading…
Cancel
Save