Add feeds display.
authorAdam Sampson <ats@offog.org>
Sat, 3 May 2003 12:59:39 +0000 (12:59 +0000)
committerAdam Sampson <ats@offog.org>
Sat, 3 May 2003 12:59:39 +0000 (12:59 +0000)
config
rawdog

diff --git a/config b/config
index caa81519d82d7acf0d25a72d53b1db0dbe048a84..b39306f291c94b8d9377bcc6b40bcd0705fe415f 100644 (file)
--- a/config
+++ b/config
@@ -22,6 +22,9 @@ outputfile /home/azz/public_html/rawdog.html
 # minutes, where N is the shortest feed period value specified below.
 userefresh 1
 
+# Whether to show the list of active feeds in the generated HTML.
+showfeeds 1
+
 # The feeds you want to watch, in the format "feed period url".
 # The period is the minimum time in minutes between updates; if less
 # than period minutes have passed, "rawdog update" will skip that feed.
diff --git a/rawdog b/rawdog
index c41278c46119cf67a4475fe0cf30ec8dd1282869..a67cff30c720133ee472e66a81950d3c51414040 100644 (file)
--- a/rawdog
+++ b/rawdog
@@ -32,6 +32,11 @@ def maybe_get(hash, key):
        if hash.has_key(key): return hash[key]
        return None
 
+def format_time(secs, config):
+       """Format a time and date nicely."""
+       t = time.localtime(secs)
+       return time.strftime(config["timeformat"], t) + ", " + time.strftime(config["dayformat"], t)
+
 class Feed:
        """An RSS feed."""
 
@@ -263,9 +268,28 @@ class Rawdog:
                        f.write('</div>\n')
 
                dw.close()
-
-               print >>f, """</div>
-<div id="footer">
+               print >>f, '</div>'
+
+               if config["showfeeds"]:
+                       print >>f, """<h2 id="feedstatsheader">Feeds</h2>
+<div id="feedstats">
+<table id="feeds">
+<tr id="feedsheader">
+<th>Feed</th><th>RSS</th><th>Last update</th><th>Next update</th>
+</tr>"""
+                       feeds = self.feeds.values()
+                       feeds.sort(lambda a, b: cmp(a.get_html_name().lower(), b.get_html_name().lower()))
+                       for feed in feeds:
+                               print >>f, '<tr class="feedsrow">'
+                               print >>f, '<td>' + feed.get_html_link() + '</td>'
+                               print >>f, '<td><a class="xmlbutton" href="' + feed.url + '">XML</a></td>'
+                               print >>f, '<td>' + format_time(feed.last_update, config) + '</td>'
+                               print >>f, '<td>' + format_time(feed.last_update + 60 * feed.period, config) + '</td>'
+                               print >>f, '</tr>'
+                       print >>f, """</table>
+</div>"""
+
+               print >>f, """<div id="footer">
 <p id="aboutrawdog">Generated by rawdog version """ + VERSION + """
 by <a href="mailto:azz@us-lot.org">Adam Sampson</a>.</p>
 </div>
@@ -302,6 +326,7 @@ def main(argv):
                "dayformat" : "%A, %d %B %Y",
                "timeformat" : "%I:%M %p",
                "userefresh" : 0,
+               "showfeeds" : 1,
                }
        for line in f.readlines():
                line = line.strip()
@@ -325,6 +350,8 @@ def main(argv):
                        config["timeformat"] = l[1]
                elif l[0] == "userefresh":
                        config["userefresh"] = int(l[1])
+               elif l[0] == "showfeeds":
+                       config["showfeeds"] = int(l[1])
                else:
                        print "Unknown config command: " + l[0]
                        return 1