From 45c8adfaf1b1938da0c04b4954628efff911546a Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Sat, 20 Sep 2003 19:01:23 +0000 Subject: [PATCH] Add "template" option. --- NEWS | 3 ++- README | 22 ++++++++++++++++------ config | 19 +++++++++++++++++++ rawdoglib/rawdog.py | 11 ++++++++++- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 0ef4be0..f7fd7aa 100644 --- a/NEWS +++ b/NEWS @@ -25,7 +25,8 @@ to have cron mail the output to you rather than putting it on a web page. Added --show-template option to show the template currently in use (so -you can customise it yourself). +you can customise it yourself), and "template" config option to allow +the user to specify their own template. - rawdog 1.2 diff --git a/README b/README index 8134c5c..513ec0d 100644 --- a/README +++ b/README @@ -6,12 +6,14 @@ feed parser. It's just an aggregator; it's not a weblog authoring tool, nor is it an NNTP gateway, outliner, mailserver or anything else. rawdog probably only runs on Unix-like systems. -rawdog reads articles from a number of feeds and writes out a single HTML file -containing the latest articles it's seen. It uses the ETags and Last-Modified -headers to avoid fetching a file that hasn't changed, and supports gzip -compression to reduce bandwidth when it has. It is configured from a simple -text file; the only state kept between invocations that can't be reconstructed -from the feeds is the ordering of articles. +rawdog reads articles from a number of feeds and writes out a single +HTML file, based on a template either provided by the user or generated +by rawdog, containing the latest articles it's seen. It uses the ETags +and Last-Modified headers to avoid fetching a file that hasn't changed, +and supports gzip compression to reduce bandwidth when it has. It is +configured from a simple text file; the only state kept between +invocations that can't be reconstructed from the feeds is the ordering +of articles. To install rawdog on your system, use distutils -- "python setup.py install". This will install the library modules that rawdog needs, and will install the @@ -32,6 +34,8 @@ to perform -- for instance, "rawdog --update --write" tells it to do the "--update" action, then the "--write" action. The actions supported are as follows: +"--help": Provide a brief summary of all the options rawdog supports. + "--update" (or "-u"): Fetch data from the feeds and store it. This could take some time if you've got lots of feeds. @@ -54,6 +58,12 @@ with different sets of options ("rawdog -u -w -c config2 -w" will first update and write with the default config, then read config2, then write again). +"--show-template" (or "-t"): Print the template currently in use to +stdout. This is useful as a starting point if you want to modify your +own template: do "rawdog -t >~/.rawdog/mytemplate" with "template +default" in your config file, and you'll get a copy of the default +template to edit. + You will want to run "rawdog -uw" periodically to fetch data and write the output file. The easiest way to do this is to add a crontab entry that looks something like this: diff --git a/config b/config index 1fdbe30..311a1d4 100644 --- a/config +++ b/config @@ -12,6 +12,19 @@ dayformat %A, %d %B # a 12-hour clock. timeformat %H:%M +# The template file to use, or "default" to use the built-in template +# (which is probably sufficient for most users). Use "rawdog -t" to show +# the template currently in use as a starting-point for customisation. +# The following strings will be replaced in the output: +# __version__ The rawdog version in use +# __refresh__ The HTML 4 header +# __items__ The aggregated items +# __feeds__ The listing of feeds +# Note that rawdog's output is always in the UTF-8 encoding, so you should +# preserve the header from the default +# template when building your own. +template default + # Where to write the output HTML to. You should place style.css in the same # directory. Specify this as "-" to write the HTML to stdout. outputfile /home/azz/public_html/rawdog.html @@ -20,9 +33,15 @@ outputfile /home/azz/public_html/rawdog.html # in the generated HTML to indicate that the page should be refreshed # automatically. If this is turned on, then the page will refresh every N # minutes, where N is the shortest feed period value specified below. +# (This works by controlling whether the default template includes +# __refresh__; if you use a custom template, __refresh__ is always +# available.) userefresh 1 # Whether to show the list of active feeds in the generated HTML. +# (This works by controlling whether the default template includes +# __feeds__; if you use a custom template, __feeds__ is always +# available.) showfeeds 1 # The time in seconds that rawdog will wait before considering a feed diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index 07acb97..6617ec1 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -252,6 +252,7 @@ class Config: "userefresh" : 0, "showfeeds" : 1, "timeout" : 30, + "template" : "default", } def __getitem__(self, key): return self.config[key] @@ -297,6 +298,8 @@ class Config: self["showfeeds"] = int(l[1]) elif l[0] == "timeout": self["timeout"] = int(l[1]) + elif l[0] == "template": + self["template"] = l[1] else: raise ConfigError("Unknown config command: " + l[0]) @@ -355,6 +358,12 @@ class Rawdog(Persistable): self.modified() def get_template(self, config): + if config["template"] != "default": + f = open(config["template"]) + template = f.read() + f.close() + return template + template = """ @@ -476,7 +485,7 @@ by Adam Sampson.

print >>f, """""" bits["feeds"] = f.getvalue() - s = get_template() + s = self.get_template(config) for k in bits.keys(): s = s.replace("__" + k + "__", bits[k]) -- 2.35.1