]> git.phdru.name Git - phdru.name/phdru.name.git/blob - make-news.py
Fix(phd.py): Change URL for Lurk
[phdru.name/phdru.name.git] / make-news.py
1 #! /usr/bin/env python
2 # -*- coding: koi8-r -*-
3
4 __author__ = "Oleg Broytman <phd@phdru.name>"
5 __copyright__ = "Copyright (C) 2006-2017 PhiloSoft Design"
6
7 import sys, os
8 from news import get_news, write_if_changed
9
10 from atom_10 import atom_10
11 from rss_20 import rss_20
12
13 lang = sys.argv[1]
14 root = sys.argv[2]
15
16 header, news_items = get_news(lang)
17
18 new_text = [header]
19
20 new_text.append("""
21 <ul>
22 """)
23
24 for item in news_items:
25     new_text.append('   <li><a href="%s">%s - %s</a></li>\n'
26                     % (item.rel_link, item.date, item.title))
27
28 new_text.append("""\
29 </ul>
30
31 <p class="head">
32 """)
33
34 if lang == "en":
35     new_text.append("""\
36 News are also available in
37 <A HREF="atom_10.xml">Atom 1.0 <img src="Graphics/atom_10.jpg" border=0></A>
38 and <A HREF="rss_20.xml">RSS 2.0 <img src="Graphics/rss_20.jpg" border=0></A>
39 formats.
40 """)
41
42 elif lang == "ru":
43     new_text.append("""\
44 Новостевая лента в форматах
45 <A HREF="atom_10.xml">Atom 1.0 <img src="../Graphics/atom_10.jpg" border=0></A>
46 и <A HREF="rss_20.xml">RSS 2.0 <img src="../Graphics/rss_20.jpg" border=0></A>.
47 """)
48
49 new_text.append("""\
50 </p>
51 #end def
52 $phd_site.respond(self)
53 """)
54
55 write_if_changed(os.path.join(root, "news.tmpl"), ''.join(new_text))
56
57
58 namespace = {
59     "title": "Oleg Broytman's Personal Page - News",
60     "baseURL": "https://phdru.name/",
61     "indexFile": "news.html",
62     "description": "",
63     "lang": lang,
64     "author": "Oleg Broytman",
65     "email": "phd@phdru.name",
66     "generator": os.path.basename(sys.argv[0]),
67     "posts": news_items,
68 }
69
70 if lang == "ru":
71     namespace["title"] = "Oleg Broytman's Personal Page - Russian News"
72     namespace["baseURL"] = baseURL = "https://phdru.name/Russian/"
73     for item in news_items:
74         item.baseURL = baseURL
75         if isinstance(item.title, bytes):
76             item.title = item.title.decode('koi8-r').encode('utf-8')
77
78 for item in news_items:
79     href_parts = item.rel_link.split('/')
80     if href_parts:
81         if href_parts[0] == '.':
82             category = "Home page"
83         elif href_parts[0] == "..":
84             category = href_parts[1]
85         else:
86             category = href_parts[0]
87         if category: item.categoryList = [category]
88
89 atom_tmpl = atom_10(searchList=[namespace])
90 rss_tmpl = rss_20(searchList=[namespace])
91
92 try:
93     unicode
94 except NameError:  # PY3
95     atom_tmpl = str(atom_tmpl)
96     rss_tmpl = str(rss_tmpl)
97 else:
98     atom_tmpl = unicode(atom_tmpl).encode('koi8-r')
99     rss_tmpl = unicode(rss_tmpl).encode('koi8-r')
100
101 write_if_changed(os.path.join(root, "atom_10.xml"), atom_tmpl)
102 write_if_changed(os.path.join(root, "rss_20.xml"), rss_tmpl)