From bc50f7f5a7f760758e5b266a614fe13830587b80 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Sat, 20 Sep 2003 16:15:26 +0000 Subject: [PATCH] Restructure output code for template usage. --- rawdoglib/rawdog.py | 58 ++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index 7f891c8..0e7f318 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -20,6 +20,7 @@ VERSION = "1.3" import feedparser from persister import Persistable, Persister import os, time, sha +from StringIO import StringIO import timeoutsocket # Override the timeout set by feedparser. @@ -355,25 +356,42 @@ class Rawdog(Persistable): outputfile = config["outputfile"] now = time.time() - f = open(outputfile + ".new", "w") + bits = { "version" : VERSION } refresh = 24 * 60 for feed in self.feeds.values(): if feed.period < refresh: refresh = feed.period - - print >>f, """ - """ - if config["userefresh"]: - print >>f, """""" - print >>f, """ + + __refresh__ + rawdog +
+__items__ +
+
+__feeds__ +
+ + +""" + + if config["userefresh"]: + bits["refresh"] = """""" + else: + bits["refresh"] = "" articles = self.articles.values() def compare(a, b): @@ -393,9 +411,7 @@ class Rawdog(Persistable): articles.sort(compare) articles = articles[:config["maxarticles"]] - print >>f, """ -
""" - + f = StringIO() dw = DayWriter(f, config) for article in articles: @@ -430,11 +446,11 @@ class Rawdog(Persistable): f.write('
\n') dw.close() - print >>f, '' + bits["items"] = f.getvalue() + f = StringIO() if config["showfeeds"]: print >>f, """

Feeds

-
@@ -448,16 +464,14 @@ class Rawdog(Persistable): print >>f, '' print >>f, '' print >>f, '' - print >>f, """
FeedRSSLast updateNext update' + format_time(feed.last_update, config) + '' + format_time(feed.last_update + 60 * feed.period, config) + '
-
""" - - print >>f, """ - -""" + print >>f, """""" + bits["feeds"] = f.getvalue() + f = open(outputfile + ".new", "w") + s = template + for k in bits.keys(): + s = s.replace("__" + k + "__", bits[k]) + print >>f, s f.close() os.rename(outputfile + ".new", outputfile) -- 2.35.1