.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)
--- /dev/null
+<?xml version="1.0" encoding="koi8-r"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <title>$title</title>
+ <id>$baseURL</id>
+ <link rel="alternate" type="text/html" href="$baseURL" />
+ <updated>${posts[0].date}T00:00:00Z</updated>
+ <author>
+ <name>$author</name>
+ <email>$email</email>
+ </author>
+ <generator uri="http://phd.pp.ru/about/make/make-news.py.txt">http://phd.pp.ru/about/</generator>
+#for $post in $posts
+ <entry>
+ <title>$post.title</title>
+ <link rel="alternate" type="text/html" href="$post.URL" />
+ <id>$post.URL</id>
+ <updated>${post.date}T00:00:00Z</updated>
+#if $post.excerpt
+ <summary type="html" mode="escaped">
+#filter WebSafe
+$post.excerpt
+<p><a href="$post.URL">Read more</a>&hellip;</p>
+#filter Filter
+ </summary>
+#end if
+#if $post.content
+ <content type="html" mode="escaped">
+#filter WebSafe
+$post.content
+#filter Filter
+ </content>
+#end if
+#for $c in $post.categoryList
+ <category term="$c" />
+#end for
+ </entry>
+#end for
+</feed>
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]
$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)
__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()
@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):
--- /dev/null
+<?xml version="1.0" encoding="koi8-r"?>
+<rss version="2.0">
+ <channel>
+ <title>$title</title>
+ <link>$baseURL</link>
+ <description>$description</description>
+ <language>$lang</language>
+ <webMaster>$author <$email></webMaster>
+ <lastBuildDate>${posts[0].rfc822_date}</lastBuildDate>
+ <generator>http://phd.pp.ru/about/make/make-news.py.txt</generator>
+#for $post in $posts
+ <item>
+ <title>$post.title</title>
+ <link>$post.URL</link>
+#if $post.excerpt or $post.content
+ <description>
+#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
+ </description>
+#end if
+ <pubDate>${post.rfc822_date}</pubDate>
+ #for $c in $post.categoryList
+ <category>$c</category>
+ #end for
+ </item>
+#end for
+ </channel>
+</rss>