annotate py/rlgnotes @ 97:fb292a0184d9

Add a page about UltraRogue.
author John "Elwin" Edwards
date Mon, 05 Apr 2021 21:57:20 -0400
parents d417016bbf73
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
1 #!/usr/bin/python3
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
2
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
3 import os
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
4 import sys
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
5 import datetime
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
6 import rlgall
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
7 import pytz
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
8
91
d417016bbf73 Small website changes.
John "Elwin" Edwards
parents: 61
diff changeset
9 navbar = '<div class="nav"><a href="/">RLGallery</a> -&gt; \
61
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
10 <a href="/notes/">Notes</a> -&gt; {0}</div>'
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
11
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
12 rsshead = """<?xml version="1.0" encoding="UTF-8"?>
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
13 <rss version="2.0">
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
14 <channel>
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
15 <title>Roguelike Gallery</title>
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
16 <description>News and notes from the Roguelike Gallery.</description>
91
d417016bbf73 Small website changes.
John "Elwin" Edwards
parents: 61
diff changeset
17 <link>https://rlgallery.org/notes/</link>
61
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
18 """
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
19
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
20 indexintro = """<p>The Gallery's blog, with news and thoughts on roguelike
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
21 games. A comment system is planned but does not exist yet. There is an
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
22 <a href="feed.rss">RSS feed</a> for the benefit of robots.</p>
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
23 """
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
24
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
25 phead = rlgall.phead.replace("/scoring/scores.css", "notes.css")
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
26
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
27 ptitle = '<h2 class="pagetitle">{0}</h2>\n'
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
28
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
29 posthead = '<h3 class="posttitle">{0}</h2>\n'
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
30
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
31 datediv = '<div class="datehead">{0}</div>\n'
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
32
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
33 def noteurl(tag):
91
d417016bbf73 Small website changes.
John "Elwin" Edwards
parents: 61
diff changeset
34 return "https://rlgallery.org/notes/" + tag + ".html"
61
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
35
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
36 def itementry(tagname, value):
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
37 return " <{0}>{1}</{0}>\n".format(tagname, value)
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
38
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
39 def fmtdate(dt):
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
40 if dt == None:
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
41 dt = datetime.datetime.now(pytz.utc)
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
42 return dt.strftime("%a, %d %b %Y %H:%M:%S %z")
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
43
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
44 def qdetag(istr):
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
45 nstart = istr.find('>')
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
46 if nstart < 0:
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
47 return istr
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
48 mstr = istr[nstart + 1:]
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
49 nend = mstr.find('<')
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
50 if nend < 0:
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
51 return mstr
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
52 return mstr[:nend]
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
53
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
54 def mkindexfile(postdata, notedir):
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
55 indexfile = open(notedir + "/index.html", "w")
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
56 postdata.sort(key=lambda m: m[2], reverse=True)
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
57 indexfile.write(phead.format("Roguelike Gallery Notes"))
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
58 indexfile.write('<body>\n<h1>Roguelike Gallery Notes</h1>\n')
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
59 indexfile.write(rlgall.navtop.format("Notes"))
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
60 indexfile.write(indexintro)
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
61 for note in postdata:
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
62 indexfile.write(posthead.format(note[1]))
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
63 datestr = note[2].strftime("%B %e, %Y")
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
64 indexfile.write(datediv.format(datestr))
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
65 if note[3][0] == '<':
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
66 indexfile.write(note[3])
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
67 else:
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
68 indexfile.write('<p>' + note[3] + '</p>')
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
69 indexfile.write('<p><a href="{0}.html">More</a></p>\n'.format(note[0]))
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
70 indexfile.write(rlgall.pend)
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
71 indexfile.close()
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
72
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
73 def mkrssfile(postdata, notedir):
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
74 rssfile = open(notedir + "/feed.rss", "w")
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
75 rssfile.write(rsshead)
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
76 nowstr = fmtdate(None)
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
77 rssfile.write("<lastBuildDate>" + nowstr + "</lastBuildDate>\n")
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
78 for post in postdata:
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
79 rssfile.write("<item>\n")
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
80 rssfile.write(itementry("title", post[1]))
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
81 rssfile.write(itementry("link", noteurl(post[0])))
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
82 rssfile.write(itementry("pubDate", fmtdate(post[2])))
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
83 rssfile.write(itementry("description", qdetag(post[3])))
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
84 rssfile.write("</item>\n")
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
85 rssfile.write('</channel>\n</rss>\n')
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
86
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
87 webdir = "/var/www/lighttpd/notes/"
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
88 if len(sys.argv) > 1:
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
89 srcdir = sys.argv[-1]
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
90 else:
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
91 srcdir = "."
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
92
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
93 if "-f" in sys.argv[1:]:
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
94 force = True
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
95 else:
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
96 force = False
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
97
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
98 metadata = []
5b4ff5680037 Add a basic blog manager.
John "Elwin" Edwards
parents:
diff changeset
99 anynew = False