From: Mikael Frykholm Date: Mon, 27 Feb 2017 19:44:13 +0000 (+0100) Subject: Added dummy method to push stuff to all subscribers X-Git-Url: https://git.frykholm.com/friends.git/commitdiff_plain/86f2d7fcc6209d25439f05b45e8c6e012308cc79 Added dummy method to push stuff to all subscribers call curl -X POST localhost/user/mikael to push all entries in the db. --- diff --git a/friends/server.py b/friends/server.py index 853e78c..70f2f14 100644 --- a/friends/server.py +++ b/friends/server.py @@ -103,6 +103,25 @@ class UserHandler(tornado.web.RequestHandler): arrow=arrow ) #digest = hmac.new() + def post(self, user): + entries = db.execute("select entry.id,text,ts from user,entry where user.id=entry.userid and user.name=?",(user,)) + + self.set_header("Content-Type", 'application/atom+xml') + out = self.render_string("templates/feed.xml", + user=user, + feed_url="{}/user/{}".format(self.settings['domain'], user), + hub_url="{}/hub".format(self.settings['domain']), + entries=entries, + arrow=arrow) + #import pdb;pdb.set_trace() + subscribers = db.execute("select callback, secret from subscriptions, user where user.id=subscriptions.userid and user.name=?",(user,)) + for url,secret in subscribers: + digest = hmac.new(secret.encode('utf8'), out, digestmod='sha1').hexdigest() + + req = httpclient.HTTPRequest(url=url, allow_nonstandard_methods=True,method='POST', body=out, headers={"X-Hub-Signature":"sha1={}".format(digest),"Content-Type": 'application/atom+xml',"Content-Length":len(out)}) + apa = httpclient.HTTPClient() + apa.fetch(req) + application = tornado.web.Application([ (r"/.well-known/host-meta", XrdHandler), (r"/.well-known/webfinger", FingerHandler), @@ -139,5 +158,4 @@ if __name__ == "__main__": db.row_factory = sqlite3.Row srv.listen(8080) tornado.ioloop.IOLoop.instance().start() - #TODO hmac.new(b'5cc324285ece71e21e9554f4056563806f6ce0b7e4ab18d0133b602f8ba7e87a',open("apa.xml","rb").read(),digestmod='sha1').hexdigest() -'b75d4733e0802629a0c15d0faa8de8fc9778cd05' queue runner +