from flask import Flask, jsonify, Response, request from camera import Camera from game import Game app = Flask(__name__) my_game = Game() my_camera = Camera() @app.route('/question', methods=['GET']) def get_question(): my_game.get_question() print(my_game.question) return jsonify(my_game.question) @app.route('/teamsize', methods=['POST']) def teamsize(): team_size = request.json my_game.set_teamsize(team_size.get('teamsize')) print(f'Teamsize: {my_game.teamsize}\n') return Response(status=200) @app.route('/scoreboard', methods=['GET']) def scoreboard(): print(my_game.scoreboard) return jsonify(my_game.scoreboard) @app.route('/check', methods=['GET']) def check(): my_camera.start_process = True my_camera.correct_field_frame = my_game.field my_camera.process() my_game.set_scoreboard(my_camera.scores) my_camera.start_process = False return jsonify(my_game.scoreboard) @app.route('/reset', methods=['GET']) def reset(): my_game.reset_game() return Response(status=200) @app.route('/scores', methods=['POST']) def get_scores(): scores = request.json my_game.add_score(scores) return Response(status=200) @app.route('/winner', methods=['GET']) def set_winner(): my_game.final_result() return jsonify(my_game.final_score) def main(): ## Router app.run(host='192.168.50.79', port=5555, debug=True) ## Postman # app.run(host='127.0.0.1', port=5555, debug=True) if __name__ == '__main__': main()