112 lines
2.6 KiB
Python
112 lines
2.6 KiB
Python
import ast
|
|
from flask import Flask, render_template, jsonify, Response, request, send_file
|
|
import time
|
|
import requests
|
|
import json
|
|
from PIL import Image
|
|
from ast import literal_eval
|
|
import ast
|
|
from io import StringIO, BytesIO
|
|
import numpy as np
|
|
import io
|
|
import cv2
|
|
import base64
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route('/')
|
|
def index():
|
|
return render_template('main.html')
|
|
|
|
@app.route("/choose-game", methods=['POST', 'GET'])
|
|
def choose_game():
|
|
forward_message = "Moving Forward"
|
|
|
|
|
|
|
|
return render_template('menu.html', forward_message=forward_message)
|
|
|
|
@app.route("/add-images", methods=['POST'])
|
|
def add_images():
|
|
return None
|
|
# TO-DO
|
|
|
|
@app.route("/rules", methods=['POST', 'GET'])
|
|
def rules():
|
|
return render_template('rules.html')
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/join-game", methods=['POST', 'GET'])
|
|
def join_game():
|
|
return None
|
|
# TO-DO
|
|
|
|
|
|
|
|
API_URL1 = "http://192.168.37.69:50000"
|
|
|
|
API_URL2 = "http://192.168.37.69:50000/port"
|
|
|
|
|
|
#------------------------------------------ Cards -----------------------------------------
|
|
def serve_pil_image(pil_img):
|
|
img_io = BytesIO()
|
|
pil_img.save(img_io, 'JPEG', quality=70)
|
|
img_io.seek(0)
|
|
return send_file(img_io, mimetype='image/jpeg')
|
|
|
|
def stringToRGB(base64_string):
|
|
imgdata = base64.b64decode(str(base64_string))
|
|
image = Image.open(io.BytesIO(imgdata))
|
|
return cv2.cvtColor(np.array(image), cv2.COLOR_BGR2RGB)
|
|
|
|
|
|
|
|
API_CARD = "http://192.168.37.69:50001/cards"
|
|
|
|
@app.route("/new-game", methods=['POST', 'GET'])
|
|
def getCards():
|
|
res = requests.get(API_CARD).json()
|
|
card = res.get('la_carte') # our port
|
|
cards_array = np.array(json.loads(card))
|
|
img = Image.fromarray(np.uint8(cards_array))
|
|
pil_img = serve_pil_image(img)
|
|
print(type(pil_img))
|
|
pil_img.direct_passthrough = False
|
|
print(type(pil_img.data))
|
|
imageStream = io.BytesIO(pil_img.data)
|
|
imageFile = Image.open(imageStream)
|
|
print(type(imageFile))
|
|
buffer = io.BytesIO()
|
|
imageFile.save(buffer, format='JPEG')
|
|
print(type(imageFile))
|
|
card = imageFile.save("./static/images/temp/card1.jpg")
|
|
return render_template('new-game.html')
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/apitest", methods=['POST', 'GET'])
|
|
def apitest():
|
|
# reqParms = request
|
|
# return render_template('test.html', param=reqParms)
|
|
x = request.get_json(silent=True)
|
|
print(json.loads(request.data.decode("utf-8")))
|
|
# log the user out
|
|
return render_template('test.html', X = x)
|
|
|
|
|
|
|
|
@app.route("/getPixels", methods=['GET'])
|
|
def getPixels():
|
|
return render_template('test.html')
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(debug = True)
|