Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added pyroutes version

  • Loading branch information...
commit 12c229339b79c952c8e6fc0b3b059bbd322773d2 1 parent 1434f6c
@klette klette authored
Showing with 69 additions and 0 deletions.
  1. +31 −0 pyroutes/app.py
  2. +38 −0 pyroutes/base.xml
View
31 pyroutes/app.py
@@ -0,0 +1,31 @@
+from pyroutes import route, settings, application
+from pyroutes.http.response import Response
+from pyroutes.template import TemplateRenderer
+import memcache
+import simplejson
+import urllib
+
+tr = TemplateRenderer()
+cache = memcache.Client(servers=['127.0.0.1:11211'])
+
+@route('/')
+def index(request):
+ fml_endpoint = 'http://graph.facebook.com/search?q="so%20starving&type=post'
+ fb_data = cache.get(fml_endpoint)
+ if not fb_data:
+ fb_response = urllib.urlopen(fml_endpoint).read()
+ fb_data = simplejson.loads(fb_response)['data']
+ cache.set(fml_endpoint, fb_data)
+ return Response(tr.render('base.xml',
+ {'ul': [
+ {'li': {
+ '#picture': {'img/src': 'https://graph.facebook.com/%s/picture' % post['from']['id']},
+ '#message': {'#msg': post['message'], '#author': post['from']['name']}
+ }
+ }
+ for post in [p for p in fb_data if 'message' in p]]
+ }))
+
+if __name__ == '__main__':
+ from pyroutes.utils import devserver
+ devserver(application)
View
38 pyroutes/base.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" ?>
+<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>
+<html xml:lang="en" xmlns:t="http://template.sesse.net/" xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<title>Klette.us - Blog, Code, Rants</title>
+<style type="text/css">
+<![CDATA[
+ .author{
+ font-style:italic;
+ }
+ li{
+ list-style: none;
+ }
+ .picture, .message{
+ float:left;
+ }
+
+]]>
+</style>
+</head>
+<body>
+ <ul>
+ <li>
+ <div>
+ <div t:id="picture" class="picture">
+ <img />
+ </div>
+ <div t:id="message" class="message">
+ <span t:id="msg"></span>:
+ <span t:id="author" class="author"></span>
+ </div>
+
+ </div>
+ </li>
+ </ul>
+
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.