#!/usr/bin/python
import re, urllib

def getBits(): 
   s = urllib.urlopen('http://notabug.com/swhack/latest').read()
   return [re.sub('&', '&amp;', re.sub('[\n\t]', ' ', x)) for x in 
           re.compile('(?s)<p>.+?</p>').findall(s)]

def deBitize(b): 
   result = []
   i = 1
   for bit in b: 
      result.append((str(i), (re.sub('<[^>]+>', '', bit)[:50]+'...', bit)))
      i += 1
   return result

def printTheThing(x): 
   print """<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/" 
xmlns:content="http://purl.org/rss/1.0/modules/content/" 
xmlns="http://purl.org/rss/1.0/">
  <channel rdf:about="http://notabug.com/swhack/latest.rdf">
    <title>The New Swhack</title>
    <link>http://notabug.com/swhack/latest</link>
    <description>Serving some sense sans sloganity since somewhen</description>
    <language>en-us</language>
    <items>
      <rdf:Seq>"""

   for item in x: 
      print """        <rdf:li rdf:resource="%s" />""" \
          % ('http://notabug.com/swhack/latest#d'+item[0])

   print """      </rdf:Seq>
    </items>
  </channel>

"""

   for item in x: 
      print """  <item rdf:about="%s">
    <title>%s</title>
    <description>%s</description>
    <link>http://notabug.com/swhack/latest</link>
    <content:encoded><![CDATA[%s]]></content:encoded>
  </item>""" % ('http://notabug.com/swhack/latest#d'+item[0], item[0], 
                   item[1][0], item[1][1])

   print """
</rdf:RDF>"""

def run(): 
   bits = getBits()
   t = deBitize(bits)
   print "Content-Type: application/xml"
   print
   printTheThing(t)

if __name__=="__main__": 
   run()
