Skip to content

Instantly share code, notes, and snippets.

@achim
Last active January 3, 2016 06:09
Show Gist options
  • Save achim/8420460 to your computer and use it in GitHub Desktop.
Save achim/8420460 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
#requires pyobjc
import tornado.ioloop
import tornado.web
from cgi import escape
from xml.sax.saxutils import quoteattr
from AppKit import *
import objc
safari_bundle = NSBundle.bundleWithPath_('/System/Library/PrivateFrameworks/Safari.framework')
readinglist_ctrl = safari_bundle.classNamed_('ReadingListController').sharedController()
def render_item(item):
string = '<li>'
string += '<a href='+quoteattr(item.urlString())+'>' + item.title() + '</a>'
if item.isUnread():
string += ' [unread]'
string += ' ' + str(item.dateAdded())
string += '</li>'
return string
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write('<ul>')
self.write(''.join(render_item(i) for i in readinglist_ctrl.allItems()))
self.write('</ul>')
application = tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
application.listen(8765)
tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment