]> oss.titaniummirror.com Git - webber.git/blobdiff - plugins/rss_feed.py
rss_feed.py: simply XML formatting
[webber.git] / plugins / rss_feed.py
index 28b0efcc7346d79b322a90cab2e18bcca570e03f..a4197b1e16fd37845f51d363ad08ede01f6a7fee 100644 (file)
@@ -1,6 +1,11 @@
 # -*- coding: iso-8859-1 -*-
 from webber import *
-import os, datetime, PyRSS2Gen
+import os, datetime
+try:
+       import PyRSS2Gen
+except ImportError:
+       print "rss_feed needs the python module PyRSS2Gen"
+       raise
 
 items = []
 
@@ -35,16 +40,18 @@ def sitemap_scan(params):
        file = params.file
        if not file.has_key("linktitle"):
                return
-       if not file.has_key("change"):
-               return
+       if file.has_key("change"):
+               change = file["change"]
+       else:
+               change = ""
 
        fname_out = os.path.join(cfg.out_dir, file.out_path)
        full_url = "http://%s/%s" % (cfg.main_url, fname_out)
        item = PyRSS2Gen.RSSItem(
                title = file["title"],
                link = full_url,
-               guid = PyRSS2Gen.Guid("%s %s" % (full_url, file["mtime"])),
-               description = file["change"],
+               guid = PyRSS2Gen.Guid("%s %s" % (full_url, file["mtime"]), isPermaLink=0),
+               description = change,
                pubDate = datetime.datetime.fromtimestamp(file["mtime"], utc),
        )
        items.append(item)
@@ -64,4 +71,8 @@ def finish(params):
                os.makedirs(cfg.out_dir)
        except:
                pass
-       rss.write_xml( open(os.path.join(cfg.out_dir, cfg.rss_file), "w"))
+       f = open(os.path.join(cfg.out_dir, cfg.rss_file), "w")
+       # Ugly XML beautification
+       s = rss.to_xml().replace("<", "\n<").replace("\n\n", "\n")[1:]
+       f.write(s)
+       f.write("\n")