From f039016ad17cc13a68e7ee96c50168967acabeba Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Sat, 7 Nov 2015 16:08:12 -0500 Subject: add the xkcd bot --- slack.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'slack.py') diff --git a/slack.py b/slack.py index e919637..c6c9faf 100644 --- a/slack.py +++ b/slack.py @@ -1,4 +1,5 @@ from flask import Flask, jsonify, request +from xkcd import get_xkcd app = Flask(__name__) app.config.from_envvar('CONF') @@ -12,5 +13,16 @@ def echo(): } return jsonify(d) +@app.route("/xkcd", methods=['POST']) +def xkcd_view(): + title, url = get_xkcd(request.form['text']) + d = {'response_type': 'in_channel', + 'text': title, + 'attachments': [ + {'image_url':"http:{0}:".format(url)} + ] + } + return jsonify(d) + if __name__=="__main__": app.run() -- cgit v1.2.3-70-g09d2