Spaces:
Running
Running
# server.py | |
# where your python app starts | |
# init project | |
from flask import Flask, jsonify, render_template, request | |
#from typing_extensions import Literal | |
#from quart import Quart, jsonify, render_template, request | |
from discord_bot import discord_bot, sendMessageToChannel | |
# from pingpong import pingpong | |
from threading import Thread | |
application = Flask(__name__) | |
#application.config['TIMEOUT'] = 1000 | |
# I've started you off with Flask, | |
# but feel free to use whatever libs or frameworks you'd like through `.requirements.txt`. | |
# unlike express, static files are automatic: http://flask.pocoo.org/docs/0.12/quickstart/#static-files | |
# http://flask.pocoo.org/docs/0.12/quickstart/#routing | |
# http://flask.pocoo.org/docs/0.12/quickstart/#rendering-templates | |
def hello(): | |
return render_template('index.html') | |
# Simple in-memory store | |
dreams = [ | |
'Find and count some sheep', | |
'Climb a really tall mountain', | |
'Wash the dishes', | |
] | |
def status(): | |
return "Hello. I am alive!" | |
def webhook(): | |
data = request.json | |
message = data.get('message', 'No message provided') | |
if 'id' in data or 'log_message' in data: | |
sendMessageToChannel(data) | |
return data | |
return jsonify({'status': 'Message sent to Discord'}) | |
def get_dreams(): | |
return jsonify(dreams) | |
# could also use the POST body instead of query string: http://flask.pocoo.org/docs/0.12/quickstart/#the-request-object | |
def add_dream(): | |
dreams.append(request.args.get('dream')) | |
return '' | |
def disclaimer(): | |
return render_template("disclaimer.html") | |
def eula(): | |
return render_template("eula.html") | |
def privacyPolicy(): | |
return render_template("privacy_policy.html") | |
def termsOfService(): | |
return render_template("terms_of_service.html") | |
# listen for requests | |
def run(): | |
if __name__ == "__main__": | |
from os import environ | |
application.run(host='0.0.0.0', port=7860) | |
t = Thread(target=run) | |
t.start() | |
# pingpong() | |
discord_bot() | |