]> git.phdru.name Git - phdru.name/phdru.name.git/blobdiff - make-news.py
Feat(blog): Encode tags
[phdru.name/phdru.name.git] / make-news.py
index e0779cf28e51e65c3ef7f369c74a4763aed8af0e..35cf42d25cbf697f7087064454e384f1371d46e0 100755 (executable)
@@ -1,16 +1,15 @@
 #! /usr/bin/env python
 # -*- coding: koi8-r -*-
 
-__version__ = "$Revision$"[11:-2]
-__revision__ = "$Id$"[5:-2]
-__date__ = "$Date$"[7:-2]
-__author__ = "Oleg Broytman <phd@phd.pp.ru>"
-__copyright__ = "Copyright (C) 2006-2009 PhiloSoft Design"
-
+__author__ = "Oleg Broytman <phd@phdru.name>"
+__copyright__ = "Copyright (C) 2006-2017 PhiloSoft Design"
 
 import sys, os
 from news import get_news, write_if_changed
 
+from atom_10 import atom_10
+from rss_20 import rss_20
+
 lang = sys.argv[1]
 root = sys.argv[2]
 
@@ -19,22 +18,21 @@ header, news_items = get_news(lang)
 new_text = [header]
 
 new_text.append("""
-<p class="head">
-   <ul>
+<ul>
 """)
 
 for item in news_items:
-   new_text.append('      <li><a href="%s">%s - %s</a></li>\n' % (item.rel_link, item.date, item.title))
+    new_text.append('   <li><a href="%s">%s - %s</a></li>\n'
+                    % (item.rel_link, item.date, item.title))
 
 new_text.append("""\
-   </ul>
-</p>
+</ul>
 
 <p class="head">
 """)
 
 if lang == "en":
-   new_text.append("""\
+    new_text.append("""\
 News are also available in
 <A HREF="atom_10.xml">Atom 1.0 <img src="Graphics/atom_10.jpg" border=0></A>
 and <A HREF="rss_20.xml">RSS 2.0 <img src="Graphics/rss_20.jpg" border=0></A>
@@ -42,7 +40,7 @@ formats.
 """)
 
 elif lang == "ru":
-   new_text.append("""\
+    new_text.append("""\
 Новостевая лента в форматах
 <A HREF="atom_10.xml">Atom 1.0 <img src="../Graphics/atom_10.jpg" border=0></A>
 и <A HREF="rss_20.xml">RSS 2.0 <img src="../Graphics/rss_20.jpg" border=0></A>.
@@ -51,45 +49,54 @@ elif lang == "ru":
 new_text.append("""\
 </p>
 #end def
-$phd_pp_ru.respond(self)
+$phd_site.respond(self)
 """)
 
 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 Broytman's Personal Page - News",
-   "baseURL": "http://phd.pp.ru/",
-   "indexFile": "news.html",
-   "description": "",
-   "lang": lang,
-   "author": "Oleg Broytman",
-   "email": "phd@phd.pp.ru",
-   "generator": os.path.basename(sys.argv[0]),
-   "posts": news_items,
+    "title": "Oleg Broytman's Personal Page - News",
+    "baseURL": "https://phdru.name/",
+    "indexFile": "news.html",
+    "description": "",
+    "lang": lang,
+    "author": "Oleg Broytman",
+    "email": "phd@phdru.name",
+    "generator": os.path.basename(sys.argv[0]),
+    "posts": news_items,
 }
 
 if lang == "ru":
-   namespace["title"] = "Oleg Broytman's Personal Page - Russian News"
-   namespace["baseURL"] = baseURL = "http://phd.pp.ru/Russian/"
-   for item in news_items:
-      item.baseURL = baseURL
+    namespace["title"] = "Oleg Broytman's Personal Page - Russian News"
+    namespace["baseURL"] = baseURL = "https://phdru.name/Russian/"
+    for item in news_items:
+        item.baseURL = baseURL
+        if isinstance(item.title, bytes):
+            item.title = item.title.decode('koi8-r').encode('utf-8')
 
 for item in news_items:
-   href_parts = item.rel_link.split('/')
-   if href_parts:
-      if href_parts[0] == '.':
-         category = "Home page"
-      elif href_parts[0] == "..":
-         category = href_parts[1]
-      else:
-         category = href_parts[0]
-      if category: item.categoryList = [category]
-
-atom_tmpl = str(atom_10(searchList=[namespace]))
+    href_parts = item.rel_link.split('/')
+    if href_parts:
+        if href_parts[0] == '.':
+            category = "Home page"
+        elif href_parts[0] == "..":
+            category = href_parts[1]
+        else:
+            category = href_parts[0]
+        if category: item.categoryList = [category]
+
+atom_tmpl = atom_10(searchList=[namespace])
+rss_tmpl = rss_20(searchList=[namespace])
+
+try:
+    unicode
+except NameError:  # PY3
+    atom_tmpl = str(atom_tmpl)
+    rss_tmpl = str(rss_tmpl)
+else:
+    atom_tmpl = unicode(atom_tmpl).encode('koi8-r')
+    rss_tmpl = unicode(rss_tmpl).encode('koi8-r')
+
 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)