]> oss.titaniummirror.com Git - webber.git/blobdiff - plugins/rss_feed.py
rss_feed.py: generate "lastBuildDate" in GMT, not local time
[webber.git] / plugins / rss_feed.py
index 3497c2ac5e1979d51518c511a0c4f6a25890953f..79fdae9fd5de6b22fddb31336c1c3d1f41afeea3 100644 (file)
@@ -17,8 +17,8 @@ def checkconfig(params):
                cfg.rss_file = "feed.rss"
 
 
+# Helper class needed for datetime.datetime to generate GMT timestamps
 ZERO = datetime.timedelta(0)
-
 class UTC(datetime.tzinfo):
     """UTC"""
 
@@ -40,33 +40,44 @@ 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)
 
 
-
 @set_hook("finish")
 def finish(params):
        rss = PyRSS2Gen.RSS2(
                title = cfg.subtitle,
                link = "http://%s" % cfg.main_url,
                description = cfg.subtitle,
-               lastBuildDate = datetime.datetime.now(),
+               lastBuildDate = datetime.datetime.now(utc),
                items = items,
        )
+       # Step one of self-reference
+       # (see http://feedvalidator.org/docs/warning/MissingAtomSelfLink.html)
+       rss.rss_attrs["xmlns:atom"] = "http://www.w3.org/2005/Atom"
+
        try:
                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:]
+       # Step two of self-reference
+       s = s.replace('<channel>', '<channel>\n<atom:link href="http://%s/%s" rel="self" type="application/rss+xml" />' % (cfg.main_url, cfg.rss_file))
+       f.write(s)
+       f.write("\n")