+import sqlite3
+import arrow
+import datetime
+from rd import RD, Link
+db = None
+#insert into user (name,email) values('mikael','mikael@frykholm.com');
+#insert into entry (userid,text) values (1,'My thoughts on ostatus');
+import tornado.options
+
+settings = {
+ "static_path": os.path.join(os.path.dirname(__file__), "static"),
+ "cookie_secret": "__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
+ "login_url": "/login",
+ "xsrf_cookies": False,
+ "domain":"https://ronin.frykholm.com",
+
+}
+class PushHandler(tornado.web.RequestHandler):
+#curl -v -k "https://ronin.frykholm.com/hub" -d "hub.callback=a" -d "hub.mode=b" -d "hub.topic=c" -d "hub.verify=d"
+ def post(self):
+ """ Someone wants to subscribe to hub_topic feed"""
+ hub_callback = self.get_argument('hub.callback')
+ hub_mode = self.get_argument('hub.mode')
+ hub_topic = self.get_argument('hub.topic')
+ hub_verify = self.get_argument('hub.verify')
+ hub_lease_seconds = self.get_argument('hub.lease_seconds','')
+ hub_secret = self.get_argument('hub.sercret','')
+ hub_verify_token = self.get_argument('hub.verify_token','')
+ if hub_mode == 'unsubscribe':
+ pass #FIXME
+ path = hub_topic.split(self.settings['domain'])[1]
+ user = path.split('user/')[1]
+ row = db.execute("select id from user where name=?",(user,)).fetchone()
+ if row:
+ db.execute("INSERT into subscriptions (userid, expires, callback, verified) values (?,?,?,?)",(row['id'],datetime.datetime.now(),hub_callback,False))
+ db.commit()
+ self.set_status(202)