from flask import Flask, jsonify, request from xkcd import get_xkcd app = Flask(__name__) app.config.from_envvar('CONF') @app.route("/echo", methods=['POST']) def echo(): d = {'response_type': 'in_channel', 'text': "I'm the echo bot!", 'attachments': [ {'text':request.form['text']} ] } return jsonify(d) @app.route("/xkcd", methods=['POST']) def xkcd_view(): comic_id = request.form['text'] title, url = get_xkcd(comic_id) d = {'response_type': 'in_channel', 'attachments': [ {'image_url':"http:{0}".format(url), 'title': title, 'title_link': 'http://www.xkcd.org/{0}'.format(comic_id) } ] } return jsonify(d) if __name__=="__main__": app.run()