Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 113 lines (99 sloc) 3.615 kb
f28b73a @mhagander Initial version of new planet code
authored
1 #!/usr/bin/env python
2 """PostgreSQL Planet Aggregator
3
4 This file contains the functions to generate HTML format output.
5 It's a fairly ugly hack compared to using a real template
6 system, but...
7
8 Copyright (C) 2008 PostgreSQL Global Development Group
9 """
10
11 import datetime
da9733f @mhagander Make the output use the full width of the page.
authored
12 import urllib
f28b73a @mhagander Initial version of new planet code
authored
13
14 class PlanetHtml:
15 def __init__(self):
16 self.items = []
17 self.feeds = []
18 self.str = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
19 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
20 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" dir="ltr">
21 <head>
22 <title>Planet PostgreSQL</title>
23 <meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" />
24 <link rel="shortcut icon" href="/favicon.ico" />
25 <link rel="alternate" type="application/rss+xml" title="Planet PostgreSQL" href="http://planet.postgresql.org/rss20.xml" />
26 <style type="text/css" media="screen" title="Normal Text">@import url("css/planet.css");</style>
27 </head>
28 <body>
da9733f @mhagander Make the output use the full width of the page.
authored
29 <div id="planetWrap">
f28b73a @mhagander Initial version of new planet code
authored
30 <div id="planetHeader">
da9733f @mhagander Make the output use the full width of the page.
authored
31 <div class="fl"><img src="http://www.postgresql.org/layout/images/hdr_left.png" alt="PostgreSQL" /></div>
f28b73a @mhagander Initial version of new planet code
authored
32 <div class="fr"><img width="210" height="80" src="http://www.postgresql.org/layout/images/hdr_right.png" alt="The world's most advanced open source database" /></div>
33 <div class="cb"></div>
34 </div>
35 <div id="planetMain">
36 """
37
38 def AddItem(self,guid,link,dat,title,author,blogurl,txt):
39 self.items.append((guid,link,dat,title,author,blogurl,txt))
40
41 def AddFeed(self,name,blogurl,feedurl):
42 self.feeds.append((name,blogurl,feedurl))
43
44 def BuildPosts(self):
45 self.str += """ <div id="planetLeft">"""
46 lastdate = None
47 for post in self.items:
48 if post[6].endswith('[...]'):
49 txt = post[6][:len(post[6])-4] + """<a href="%s">continue reading...</a>]""" % (post[1])
50 else:
51 txt = post[6]
52
53 if lastdate == None or lastdate != post[2].date():
54 self.str += """
55 <div class="planetNewDate">%s</div>""" % (post[2].date())
56 lastdate = post[2].date()
57
58 if post[5]:
59 posterstr = """<a class="author" href="%s">%s</a>""" % (post[5], post[4])
60 else:
61 posterstr = post[4]
62
63 self.str += """
64 <div class="planetPost">
65 <div class="planetPostTitle"><a href="%s">%s</a></div>
66 <div class="planetPostAuthor">
67 <div class="ppa_top">&nbsp;</div>
da9733f @mhagander Make the output use the full width of the page.
authored
68 <p>Posted by %s on <span class="date">%s at %s</span></p>
69 <div class="ppa_bottom">&nbsp;</div>
f28b73a @mhagander Initial version of new planet code
authored
70 </div>
71 <div class="planetPostContent">%s</div>
da9733f @mhagander Make the output use the full width of the page.
authored
72 <div class="cl"></div>
f28b73a @mhagander Initial version of new planet code
authored
73 </div>""" % (post[1], post[3], posterstr, post[2].date(), post[2].time(), txt)
74
75 self.str += """ </div>"""
76
da9733f @mhagander Make the output use the full width of the page.
authored
77 def quoteurl(self, str):
78 p = str.split(":",2)
79 return p[0] + ":" + urllib.quote(p[1])
80
f28b73a @mhagander Initial version of new planet code
authored
81 def BuildRight(self):
82 self.str += """ <div id="planetRight">
83 <div class="planetRightTitle">Subscriptions</div>
84 <ul>"""
85 for feed in self.feeds:
86 self.str += "<li>"
87 if feed[1] != '':
da9733f @mhagander Make the output use the full width of the page.
authored
88 self.str += """<a href="%s">%s</a>""" % (self.quoteurl(feed[1]), feed[0])
f28b73a @mhagander Initial version of new planet code
authored
89 else:
90 self.str += feed[0]
91 self.str += """
da9733f @mhagander Make the output use the full width of the page.
authored
92 <a href="%s"><img src="http://www.postgresql.org/layout/images/ico_rss.png" alt="rss" /></a></li>""" % (feed[2])
93 self.str += """
94 </ul>
f28b73a @mhagander Initial version of new planet code
authored
95 <div class="planetRightTitle">Feeds</div>
96 <ul>
da9733f @mhagander Make the output use the full width of the page.
authored
97 <li><a href="rss20.xml">Planet PostgreSQL</a> <a href="rss20.xml"><img src="http://www.postgresql.org/layout/images/ico_rss.png" alt="rss" /></a></li>
f28b73a @mhagander Initial version of new planet code
authored
98 </ul>
99 </div>
100 """
101 def WriteFile(self,filename):
102 self.BuildRight()
da9733f @mhagander Make the output use the full width of the page.
authored
103 self.BuildPosts()
f28b73a @mhagander Initial version of new planet code
authored
104 self.str += """
105 </div>
106 </div>
107 </body>
108 </html>
109 """
110 f = open(filename,"w")
111 f.write(self.str)
112 f.close()
Something went wrong with that request. Please try again.