diff --git a/main_controller.py b/main_controller.py index cd96288..0c36ce0 100644 --- a/main_controller.py +++ b/main_controller.py @@ -1,24 +1,32 @@ import asyncio, time, datetime, games, json, threading -from flask import Flask, url_for, Response +from flask import Flask, url_for, Response, render_template, request, jsonify +from flask_socketio import SocketIO, emit app = Flask("the-prestige") +app.config['SECRET KEY'] = 'dev' +socketio = SocketIO(app) @app.route('/') -def hello(): - return url_for("boop") +def index(): + return render_template("index.html") @app.route("/gotoboop") -def boop(): +def get_game_states(): return states_to_send -thread2 = threading.Thread(target=app.run) +@socketio.on("recieved") +def do_another_thing(data): + print(data) + +thread2 = threading.Thread(target=socketio.run,args=(app,)) thread2.start() master_games_dic = {} #key timestamp : (game game, {} state) -states_to_send = {} + def update_loop(): while True: + states_to_send = {} game_times = iter(master_games_dic.copy().keys()) for game_time in game_times: this_game, state = master_games_dic[game_time] @@ -41,7 +49,7 @@ def update_loop(): state["update_pause"] = 2 state["pitcher"] = "-" state["batter"] = "-" - if state["top_of_inning"]: + if not state["top_of_inning"]: state["display_inning"] -= 1 if state["update_pause"] == 1: @@ -91,4 +99,5 @@ def update_loop(): state["update_pause"] -= 1 - time.sleep(6) \ No newline at end of file + socketio.emit("states_update", states_to_send) + time.sleep(1) \ No newline at end of file diff --git a/static/games_page.css b/static/games_page.css new file mode 100644 index 0000000..92fb9c8 --- /dev/null +++ b/static/games_page.css @@ -0,0 +1,43 @@ +@import url('https://fonts.googleapis.com/css2?family=Alegreya&display=swap'); +body { + background-image: url("prism.png"); +} +/* Background pattern from Toptal Subtle Patterns */ + +.container { + font-family: 'Alegreya', serif; + display: grid; + grid-template-columns: 1fr 1fr 1fr; + grid-template-rows: 100px 300px; + grid-gap: 50px 30px; /*space between rows, then columns*/ + align-items: center; + justify-items: center; + grid-auto-rows: 300px; + grid-auto-flow: row; +} + +.h1 { + margin: auto; + width: 45%; + font-family: 'Alegreya', serif; +} + +.emptyslot { + border: 2px dashed white; + border-radius: 15px; + align-self: stretch; + justify-self: stretch; + text-align: center; + color: white; +} + +.game { + font-family: 'Alegreya', serif; + color: white; +} + +h2 { + font-family: 'Alegreya', serif; + color: white; + text-align: center; +} \ No newline at end of file diff --git a/static/loader.js b/static/loader.js new file mode 100644 index 0000000..550dfae --- /dev/null +++ b/static/loader.js @@ -0,0 +1,41 @@ +$(document).ready(function (){ + var socket = io.connect(); + var gameslist = []; + var maxslot = 3; + var grid = document.getElementById("container"); + + + socket.on('connect', function () { + socket.emit('recieved', { data: 'I\'m connected!' }); + }); + + socket.on("states_update", function (json) { //json is an object containing all game updates + for (const timestamp in json) { + if (!gameslist.includes(timestamp)) { //adds game to list if not there already + gameslist.push(timestamp) + var gridBoxes = grid.children; + for (var slotnum = 3; slotnum <= maxslot; slotnum++) { + if (gridBoxes[slotnum].className == "emptyslot") { + insertGame(slotnum, json[timestamp], timestamp); + maxslot += 1; + break; + }; + }; + }; + + for (var slotnum = 3; slotnum <= maxslot; slotnum++) { + if (grid.children[slotnum].timestamp == timestamp) { + console.log(json[timestamp].update_text) + grid.children[slotnum].textContent = json[timestamp].update_text; + }; + }; + }; + }); + + const insertGame = (gridboxnum, gamestate, timestamp) => { + var thisBox = grid.children[gridboxnum]; + thisBox.className = "game"; + thisBox.timestamp = timestamp + thisBox.textContent = gamestate.update_text; + }; +}); \ No newline at end of file diff --git a/static/prism.png b/static/prism.png new file mode 100644 index 0000000..0f02b16 Binary files /dev/null and b/static/prism.png differ diff --git a/static/repeated-square-dark.png b/static/repeated-square-dark.png new file mode 100644 index 0000000..31f2735 Binary files /dev/null and b/static/repeated-square-dark.png differ diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..af42576 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,32 @@ + + +
+ + + + +