Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: ee56632bf9
Fetching contributors…

Cannot retrieve contributors at this time

36 lines (31 sloc) 1.207 kb
import tornado.web
import tornado.httpclient
import tornado.ioloop
import lxml.etree
import re
import os
class MainHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):
http = tornado.httpclient.AsyncHTTPClient()
http.fetch("https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=mfeathers",
callback=self.on_response)
def on_response(self, response):
if response.error: raise tornado.web.HTTPError(500)
xml = lxml.etree.fromstring(response.body)
items = xml.xpath('//item')
for item in items:
title = item.find('title')
if title is not None and re.search(r'mfeathers:\s+@geepawhill\s+http', title.text, flags=re.I):
title.text = title.text.split()[2]
else:
item.getparent().remove(item)
self.set_header('Content-Type', 'application/rss+xml; charset=utf-8')
self.write(lxml.etree.tostring(xml))
self.finish()
application = tornado.web.Application([
(r"/", MainHandler)
])
if __name__ == '__main__':
application.listen(os.environ.get("PORT", 8888))
tornado.ioloop.IOLoop.instance().start()
Jump to Line
Something went wrong with that request. Please try again.