Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dogfacts Slack Bot
from flask import *
import random
import json
app = Flask(__name__)
@app.before_request
def before_request():
raw_text = open('facts.txt').read()
g.facts = raw_text.split('\n')
@app.route("/fact")
def getFact():
text = request.args.get('text',None)
num_facts = 1
if text in list(map(str,range(2,10))):
num_facts = int(text)
response_text=""
for i in range(num_facts):
response_text += "{}\n".format(random.choice(g.facts))
response = {
"response_type": "in_channel",
"text": response_text
}
json_response = json.dumps(response)
return Response(json_response, mimetype='application/json')
app.run(debug=True, host="0.0.0.0", port=4101)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.