From: Oleg Broytman Date: Thu, 16 Mar 2006 21:04:51 +0000 (+0000) Subject: News feeds in Atom 1.0 and RSS 2.0 formats. X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=ee8faee8038946953ffcae196c3c9b2173506ea4;p=phdru.name%2Fphdru.name.git News feeds in Atom 1.0 and RSS 2.0 formats. git-svn-id: file:///home/phd/archive/SVN/phdru.name/scripts@31 7bb0bf08-9e0d-0410-b083-99cee3bf18b8 --- diff --git a/Makefile b/Makefile index 253ab74..dfe6905 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ phd.pp.ru: phd_pp_ru.py news blog html .PHONY: news -news: ../htdocs/phd.pp.ru/news.tmpl ../htdocs/phd.pp.ru/Russian/news.tmpl +news: atom_10.py rss_20.py ../htdocs/phd.pp.ru/news.tmpl ../htdocs/phd.pp.ru/Russian/news.tmpl ../htdocs/phd.pp.ru/news.tmpl: news_en @(umask 022; PYTHONPATH=. ./make-news.py en ../htdocs/phd.pp.ru) diff --git a/atom_10.tmpl b/atom_10.tmpl new file mode 100644 index 0000000..eadc7ce --- /dev/null +++ b/atom_10.tmpl @@ -0,0 +1,38 @@ + + + $title + $baseURL + + ${posts[0].date}T00:00:00Z + + $author + $email + + http://phd.pp.ru/about/ +#for $post in $posts + + $post.title + + $post.URL + ${post.date}T00:00:00Z +#if $post.excerpt + +#filter WebSafe +$post.excerpt +<p><a href="$post.URL">Read more</a>&hellip;</p> +#filter Filter + +#end if +#if $post.content + +#filter WebSafe +$post.content +#filter Filter + +#end if +#for $c in $post.categoryList + +#end for + +#end for + diff --git a/make-news.py b/make-news.py index a1169ed..14c3cf7 100755 --- a/make-news.py +++ b/make-news.py @@ -10,7 +10,10 @@ __copyright__ = "Copyright (C) 2006 PhiloSoft Design" import sys, os from news import get_news, write_if_changed -header, news_items = get_news(sys.argv[1]) +lang = sys.argv[1] +root = sys.argv[2] + +header, news_items = get_news(lang) new_text = [header] @@ -29,4 +32,23 @@ new_text.append("""\ $phd_pp_ru.respond(self) """) -write_if_changed(os.path.join(sys.argv[2], "news.tmpl"), ''.join(new_text)) +write_if_changed(os.path.join(root, "news.tmpl"), ''.join(new_text)) + + +from atom_10 import atom_10 +from rss_20 import rss_20 + +namespace = { + "title": "Oleg Broytmann's Personal Page - News", + "baseURL": "http://phd.pp.ru/news.html", + "description": "", + "lang": lang, + "author": "Oleg Broytmann", + "email": "phd@phd.pp.ru", + "posts": news_items, +} + +atom_tmpl = str(atom_10(searchList=[namespace])) +write_if_changed(os.path.join(root, "atom_10.xml"), atom_tmpl) +rss_tmpl = str(rss_20(searchList=[namespace])) +write_if_changed(os.path.join(root, "rss_20.xml"), rss_tmpl) diff --git a/news.py b/news.py index 9e47cb3..b091cbd 100644 --- a/news.py +++ b/news.py @@ -10,12 +10,28 @@ __docformat__ = "epytext en" __all__ = ["get_news", "write_if_changed"] +from datetime import date +from urlparse import urljoin + class NewsItem(object): + excerpt = None + content = None + categoryList = [] + def __init__(self, date, title, rel_link): self.date = date self.title = title self.rel_link = rel_link + def URL(self): + return urljoin("http://phd.pp.ru/", self.rel_link) + + def rfc822_date(self): + y, m, d = self.date.split('-') + d = date(int(y), int(m), int(d)) + return d.strftime("%a, %d %b %Y %H:%M:%S +0300") + + def get_news_header(lang): news_tmpl_file = open("news.tmpl-%s" % lang, 'r') header = news_tmpl_file.read() @@ -44,7 +60,7 @@ def get_news(lang): @return: a tuple of (lnaguge-dependent header, a list of new items) """ - return get_news_header(), get_news_items() + return get_news_header(lang), get_news_items(lang) def write_if_changed(filename, new_text): diff --git a/rss_20.tmpl b/rss_20.tmpl new file mode 100644 index 0000000..22692ea --- /dev/null +++ b/rss_20.tmpl @@ -0,0 +1,34 @@ + + + + $title + $baseURL + $description + $lang + $author <$email> + ${posts[0].rfc822_date} + http://phd.pp.ru/about/make/make-news.py.txt +#for $post in $posts + + $post.title + $post.URL +#if $post.excerpt or $post.content + +#filter WebSafe +#if $post.excerpt +$post.excerpt +<p><a href="$post.URL">Read more</a>&hellip;</p> +#elif $post.content +$post.content +#end if +#filter Filter + +#end if + ${post.rfc822_date} + #for $c in $post.categoryList + $c + #end for + +#end for + +