X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=plugins%2Frss_feed.py;h=580d3040925ec0e07af77fd8af67eab82add60b4;hb=509ed07cacbbd56ade07db72f21915920760fc02;hp=a8adbec8bb068ce3e7ddd29bdd1e02a14d1d0aad;hpb=081d468ad899679ab2adcfd74ec47bd29a6d4486;p=webber.git diff --git a/plugins/rss_feed.py b/plugins/rss_feed.py index a8adbec..580d304 100644 --- a/plugins/rss_feed.py +++ b/plugins/rss_feed.py @@ -8,6 +8,7 @@ except ImportError: raise items = [] +max_age = 0 @set_hook("checkconfig") @@ -15,6 +16,12 @@ def checkconfig(params): if not cfg.has_key("rss_file"): log('no "rss_file:" configured, using "feed.rss":', 4) cfg.rss_file = "feed.rss" + if not cfg.has_key("rss_max_items"): + cfg.rss_max_items = 0 + if cfg.has_key("rss_max_age_days"): + import time + global max_age + max_age = int(time.time()) - int(cfg.rss_max_age_days)*86400 # Helper class needed for datetime.datetime to generate GMT timestamps @@ -38,6 +45,8 @@ def sitemap_scan(params): global items file = params.file + if max_age and file["mtime"] < max_age: + return if not file.has_key("linktitle"): return if file.has_key("change"): @@ -52,13 +61,26 @@ def sitemap_scan(params): link = full_url, guid = PyRSS2Gen.Guid("%s %s" % (full_url, file["mtime"]), isPermaLink=0), description = change, - pubDate = datetime.datetime.fromtimestamp(file["mtime"], utc), + pubDate = file["mtime"] ) items.append(item) @set_hook("finish") def finish(params): + global items + # Sort items by pubDate, which still holds the mtime + items.sort(key=lambda i: i.pubDate, reverse=True) + + # Limit to requested number + count = int(cfg.rss_max_items) + if count: + items = items[:count] + + # convert mtime to real pupDate + for i in items: + i.pubDate = datetime.datetime.fromtimestamp(i.pubDate, utc) + rss = PyRSS2Gen.RSS2( title = cfg.subtitle, link = "http://%s" % cfg.main_url,