stack-monitor: creation of the stack.
[slapos.git] / stack / monitor / status2rss.py
1 import datetime
2 import uuid
3 import PyRSS2Gen
4 import sys
5 from email.utils import parsedate_tz, mktime_tz
6 import base64
7
8 # Based on http://thehelpfulhacker.net/2011/03/27/a-rss-feed-for-your-crontabs/
9
10 # ### Defaults
11 TITLE = sys.argv[1]
12 LINK = sys.argv[2]
13 DESCRIPTION = TITLE
14
15 items = []
16
17 while 1:
18 try:
19 line = sys.stdin.readline()
20 except KeyboardInterrupt:
21 break
22
23 if not line:
24 break
25
26 time, desc = line.split(',', 1)
27
28 rss_item = PyRSS2Gen.RSSItem(
29 title = desc,
30 description = "%s, %s" % (time, desc),
31 link = LINK,
32 pubDate = datetime.datetime.fromtimestamp(mktime_tz(parsedate_tz(time))),
33 guid = PyRSS2Gen.Guid(base64.b64encode("%s, %s" % (time, desc)))
34 )
35 items.append(rss_item)
36
37 ### Build the rss feed
38 rss_feed = PyRSS2Gen.RSS2 (
39 title = TITLE,
40 link = LINK,
41 description = DESCRIPTION,
42 lastBuildDate = datetime.datetime.utcnow(),
43 items = items
44 )
45
46 print rss_feed.to_xml()