Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ktane-solver/main.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
70 lines (57 sloc)
1.94 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import datetime | |
import json | |
from process import start_proc | |
from process import write_empty | |
from flask import Flask | |
from flask import request | |
from flask import make_response | |
from flask import Response | |
from flask import jsonify | |
from flask import send_from_directory | |
app = Flask(__name__) | |
# 404 Not Found - Nothing at the URL | |
# 405 Method Not Allowed - Wrong URL, not a POST accepting URL | |
# 500 - Server error - Something is broken in your code | |
apikey = "d7N^}r4;spD3zSn#&u)Gg#:a/" | |
@app.route('/') | |
def index(): | |
return open("html/index.html", "r").read() | |
@app.route('/time', methods=['GET','POST']) | |
def subdomain(): | |
return '\n\nThe time is: ' + str(datetime.datetime.now()) | |
@app.route('/help') | |
def help(): | |
return open("html/help.html", "r").read() | |
@app.route('/files') | |
def files(): | |
return open("html/files.html", "r").read() | |
@app.route('/dev') | |
def dev(): | |
return open("html/dev.html", "r").read() | |
@app.route('/privacy') | |
def privacy(): | |
return open("html/privacy.html", "r").read() | |
@app.route('/api', methods=['GET','POST']) | |
def webhook(): | |
if request.method == 'POST': | |
req = request.get_json(force=True) | |
password = request.headers['password'] | |
if password != apikey: | |
print("bad api key") | |
return {"fulfillmentText": "Bad API Key. Please use a legitament request."}, 401 | |
intent = req["queryResult"]["intent"]["displayName"] | |
text = req["queryResult"]["queryText"] | |
sessionID = req["session"] | |
if intent == "start": | |
write_empty(sessionID) | |
results = {"fulfillmentText": "Okay, start the bomb now. Complete data entry first."} | |
else: | |
results = start_proc(req, text, sessionID) | |
return (jsonify(results)) | |
else: | |
return open("html/api.html", "r").read() | |
if __name__ == '__main__': | |
port = int(os.getenv('PORT', 5000)) | |
print("Starting app on port %d" % port) | |
app.run(debug=False, port=port, host='0.0.0.0') |