root/confluence/feedfilters/shfiction.py

Revision 648, 1.4 kB (checked in by confluence, 11 months ago)

wonky quotes

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2
3# This filter converts the Strange Horizons new fiction page to an rss feed.
4# Don't be a jerk; set the update period to at least one day.  It only updates once a week.
5#
6# Written by Adrianna Pinska
7# Licence: GPLv3
8
9import sys
10import cgi
11import re
12import time
13
14storypattern = re.compile('<p class="contents-title"><a href="([^"]*)">(.*?)</a></p>\n *<p class="contents-author">([^<]*)</p>\n *<p class="contents-date">([^<]*)</p>\n *<p class="contents-pullquote">(.*?)</p>\n *', re.DOTALL)
15text = sys.stdin.read()
16stories = storypattern.findall(text)
17
18print """<?xml version="1.0" encoding="UTF-8"?>
19<rss version="2.0">
20  <channel>
21    <title>Strange Horizons Fiction</title>
22    <link>http://www.strangehorizons.com/fiction.shtml</link>
23    <description>New fiction from Strange Horizons</description>
24    <language>en-us</language>
25    <ttl>1440</ttl>"""
26
27for link, title, attribution, date, blurb in stories:
28    feed_title = "%s %s" % (cgi.escape(title), attribution)
29    feed_date = time.strftime("%a, %d %B %Y %H:%M:%S", time.strptime(date, "%d %B %Y"))
30    text = cgi.escape(blurb)
31    text = text.replace("\x92","&apos;")
32    print """  <item>
33    <title>%s</title>
34    <description>%s</description>
35    <pubDate>%s</pubDate>
36    <guid>%s</guid>
37    <link>%s</link>
38  </item>""" % (feed_title, text, feed_date, link, link)
39
40print """  </channel>
41</rss>"""
Note: See TracBrowser for help on using the browser.