Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Dogfacts Slack Bot
from flask import *
import random
import json
app = Flask(__name__)
def before_request():
raw_text = open('facts.txt').read()
g.facts = raw_text.split('\n')
def getFact():
text = request.args.get('text',None)
num_facts = 1
if text in list(map(str,range(2,10))):
num_facts = int(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'), host="", 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.