Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5bac025624 | |||
| 0d3921e7cf | |||
| f17e221ad3 | |||
| 1c2028fa85 | |||
| 9fe94057ff | |||
| e355693613 | |||
| 468a03e646 | |||
| d89d674b2a | |||
| 7b5bde447a | |||
| 975ac4d4ec | |||
| 8611471360 | |||
| 18802f6ef5 | |||
| 4304954bc3 | |||
| 90cccf581a | |||
| a3ee38d774 | |||
| 5beb7e2b44 | |||
| c926821e1a | |||
| a21bb3cdcc | |||
| 148bdaefc4 | |||
| e645cb2b08 | |||
| 55b5b166d4 | |||
| 2ad85d5b51 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,7 +1,8 @@
|
|||||||
/nhle_scoreboard_response.txt
|
/nhle_scoreboard_response.txt
|
||||||
/nhle_standings_response.txt
|
/nhle_standings_response.txt
|
||||||
/nhl_standings.db
|
/app/data/nhl_standings.db
|
||||||
/scoreboard_data.json
|
/app/data/scoreboard_data.json
|
||||||
/__pycache__
|
/__pycache__
|
||||||
/app/__pycache__
|
/app/__pycache__
|
||||||
/app/scoreboard/__pycache__
|
/app/scoreboard/__pycache__
|
||||||
|
nhl_standings.db
|
||||||
|
|||||||
@@ -14,12 +14,11 @@ COPY . /app
|
|||||||
# Install any needed dependencies specified in requirements.txt
|
# Install any needed dependencies specified in requirements.txt
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
# Create the directory for scoreboard data
|
||||||
|
RUN mkdir -p app/data
|
||||||
|
|
||||||
# Expose the Flask port
|
# Expose the Flask port
|
||||||
EXPOSE 2897
|
EXPOSE 2897
|
||||||
|
|
||||||
# Copy static files and templates
|
|
||||||
COPY ./templates /app/templates
|
|
||||||
COPY ./static /app/static
|
|
||||||
|
|
||||||
# Run the Flask application
|
# Run the Flask application
|
||||||
CMD ["python", "app.py"]
|
CMD ["python", "run.py"]
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ This web application displays live NHL game scores, team statistics, and game st
|
|||||||
3. Run the application:
|
3. Run the application:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python app.py
|
python run.py
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Open your web browser and navigate to `http://localhost:2897` to view the scoreboard.
|
4. Open your web browser and navigate to `http://localhost:2897` to view the scoreboard.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from flask import render_template, jsonify
|
|||||||
from app.scoreboard.process_data import extract_game_info
|
from app.scoreboard.process_data import extract_game_info
|
||||||
import json
|
import json
|
||||||
|
|
||||||
SCOREBOARD_DATA_FILE = 'scoreboard_data.json'
|
SCOREBOARD_DATA_FILE = 'app/data/scoreboard_data.json'
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ import requests
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import json
|
import json
|
||||||
|
|
||||||
SCOREBOARD_DATA_FILE = 'scoreboard_data.json'
|
SCOREBOARD_DATA_FILE = 'app/data/scoreboard_data.json'
|
||||||
|
|
||||||
def get_scoreboard_data():
|
def get_scoreboard_data():
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
start_time_evening = now.replace(hour=23, minute=0, second=0, microsecond=0) # 7:00 PM EST
|
start_time_evening = now.replace(hour=23, minute=00, second=0, microsecond=0) # 7:00 PM EST
|
||||||
end_time_evening = now.replace(hour=8, minute=0, second=0, microsecond=0) # 3:00 AM EST
|
end_time_evening = now.replace(hour=8, minute=00, second=0, microsecond=0) # 3:00 AM EST
|
||||||
|
|
||||||
if now >= start_time_evening or now < end_time_evening:
|
if now >= start_time_evening or now < end_time_evening:
|
||||||
# Use now URL
|
# Use now URL
|
||||||
|
|||||||
@@ -7,18 +7,19 @@ def extract_game_info(scoreboard_data):
|
|||||||
|
|
||||||
extracted_info = []
|
extracted_info = []
|
||||||
for game in scoreboard_data.get("games", []):
|
for game in scoreboard_data.get("games", []):
|
||||||
|
game_state = convert_game_state(game["gameState"])
|
||||||
extracted_info.append({
|
extracted_info.append({
|
||||||
"Home Team": game["homeTeam"]["name"]["default"],
|
"Home Team": game["homeTeam"]["name"]["default"],
|
||||||
"Home Score": game["homeTeam"]["score"],
|
"Home Score": game["homeTeam"]["score"] if game_state != "PRE" else "N/A",
|
||||||
"Away Team": game["awayTeam"]["name"]["default"],
|
"Away Team": game["awayTeam"]["name"]["default"],
|
||||||
"Away Score": game["awayTeam"]["score"],
|
"Away Score": game["awayTeam"]["score"] if game_state != "PRE" else "N/A",
|
||||||
"Home Logo": game["homeTeam"]["logo"],
|
"Home Logo": game["homeTeam"]["logo"],
|
||||||
"Away Logo": game["awayTeam"]["logo"],
|
"Away Logo": game["awayTeam"]["logo"],
|
||||||
"Game State": convert_game_state(game["gameState"]),
|
"Game State": game_state,
|
||||||
"Period": process_period(game),
|
"Period": process_period(game),
|
||||||
"Time Remaining": process_time_remaining(game),
|
"Time Remaining": process_time_remaining(game),
|
||||||
"Time Running": game["clock"]["running"],
|
"Time Running": game["clock"]["running"] if game_state == "LIVE" else "N/A",
|
||||||
"Intermission": game["clock"]["inIntermission"],
|
"Intermission": game["clock"]["inIntermission"] if game_state == "LIVE" else "N/A",
|
||||||
"Priority": calculate_game_priority(game),
|
"Priority": calculate_game_priority(game),
|
||||||
"Start Time": process_start_time(game),
|
"Start Time": process_start_time(game),
|
||||||
"Home Record": game["homeTeam"]["record"] if game["gameState"] in ["PRE", "FUT"] else "N/A",
|
"Home Record": game["homeTeam"]["record"] if game["gameState"] in ["PRE", "FUT"] else "N/A",
|
||||||
@@ -27,7 +28,7 @@ def extract_game_info(scoreboard_data):
|
|||||||
"Away Shots": game["awayTeam"]["sog"] if game["gameState"] not in ["PRE", "FUT"] else 0,
|
"Away Shots": game["awayTeam"]["sog"] if game["gameState"] not in ["PRE", "FUT"] else 0,
|
||||||
"Home Power Play": get_power_play_info(game, game["homeTeam"]["name"]["default"]),
|
"Home Power Play": get_power_play_info(game, game["homeTeam"]["name"]["default"]),
|
||||||
"Away Power Play": get_power_play_info(game, game["awayTeam"]["name"]["default"]),
|
"Away Power Play": get_power_play_info(game, game["awayTeam"]["name"]["default"]),
|
||||||
"Last Period Type": get_game_outcome(game)
|
"Last Period Type": get_game_outcome(game, game_state)
|
||||||
})
|
})
|
||||||
|
|
||||||
# Sort games based on priority
|
# Sort games based on priority
|
||||||
@@ -70,8 +71,8 @@ def get_power_play_info(game, team_name):
|
|||||||
return f"PP {game['situation']['timeRemaining']}"
|
return f"PP {game['situation']['timeRemaining']}"
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def get_game_outcome(game):
|
def get_game_outcome(game, game_state):
|
||||||
return game["gameOutcome"]["lastPeriodType"] if game["gameState"] == "FINAL" else "N/A"
|
return game["gameOutcome"]["lastPeriodType"] if game_state == "FINAL" else "N/A"
|
||||||
|
|
||||||
def calculate_game_priority(game):
|
def calculate_game_priority(game):
|
||||||
# Return 0 if game is in certain states
|
# Return 0 if game is in certain states
|
||||||
@@ -95,10 +96,10 @@ def calculate_game_priority(game):
|
|||||||
home_score = game["homeTeam"]["score"]
|
home_score = game["homeTeam"]["score"]
|
||||||
away_score = game["awayTeam"]["score"]
|
away_score = game["awayTeam"]["score"]
|
||||||
score_difference = abs(home_score - away_score)
|
score_difference = abs(home_score - away_score)
|
||||||
score_total = (home_score + away_score) * 20
|
score_total = (home_score + away_score) * 25
|
||||||
|
|
||||||
# Calculate the base priority based on period
|
# Calculate the base priority based on period
|
||||||
base_priority = {4: 400, 3: 300, 2: 200}.get(period, 100)
|
base_priority = {5: 450, 4: 400, 3: 300, 2: 200}.get(period, 100)
|
||||||
|
|
||||||
# Adjust base priority based on score difference
|
# Adjust base priority based on score difference
|
||||||
if score_difference > 3:
|
if score_difference > 3:
|
||||||
@@ -113,7 +114,9 @@ def calculate_game_priority(game):
|
|||||||
base_priority += 100
|
base_priority += 100
|
||||||
|
|
||||||
# Calculate time priority
|
# Calculate time priority
|
||||||
time_priority = (1200 - time_remaining) / 20
|
time_multiplier = {4: 2, 3: 2, 2: 1.5}.get(period, 0.75)
|
||||||
|
|
||||||
|
time_priority = ((1200 - time_remaining) / 20) * time_multiplier
|
||||||
|
|
||||||
# Calculate the final priority
|
# Calculate the final priority
|
||||||
final_priority = int(base_priority + time_priority - matchup_adjustment + score_total)
|
final_priority = int(base_priority + time_priority - matchup_adjustment + score_total)
|
||||||
@@ -121,7 +124,7 @@ def calculate_game_priority(game):
|
|||||||
return final_priority
|
return final_priority
|
||||||
|
|
||||||
def get_team_standings(team_name):
|
def get_team_standings(team_name):
|
||||||
conn = sqlite3.connect("nhl_standings.db")
|
conn = sqlite3.connect("app/data/nhl_standings.db")
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT league_sequence, league_l10_sequence
|
SELECT league_sequence, league_l10_sequence
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ def extract_standings_info():
|
|||||||
|
|
||||||
def update_nhl_standings():
|
def update_nhl_standings():
|
||||||
# Connect to SQLite database
|
# Connect to SQLite database
|
||||||
conn = sqlite3.connect("nhl_standings.db")
|
conn = sqlite3.connect("app/data/nhl_standings.db")
|
||||||
|
|
||||||
# Create standings table if it doesn't exist
|
# Create standings table if it doesn't exist
|
||||||
create_standings_table(conn)
|
create_standings_table(conn)
|
||||||
|
|||||||
@@ -16,31 +16,73 @@ function fetchScoreboardData() {
|
|||||||
|
|
||||||
// Function to update scoreboard with fetched data
|
// Function to update scoreboard with fetched data
|
||||||
function updateScoreboard(data) {
|
function updateScoreboard(data) {
|
||||||
var liveGamesSection = document.getElementById("live-games-section");
|
var liveGamesSection = document.getElementById('live-games-section');
|
||||||
var preGamesSection = document.getElementById('pre-games-section');
|
var preGamesSection = document.getElementById('pre-games-section');
|
||||||
var finalGamesSection = document.getElementById('final-games-section');
|
var finalGamesSection = document.getElementById('final-games-section');
|
||||||
|
|
||||||
if (liveGamesSection) {
|
if (liveGamesSection) {
|
||||||
var liveGamesExist = data && data.live_games && data.live_games.length > 0;
|
var liveGamesExist = data && data.live_games && data.live_games.length > 0;
|
||||||
if (liveGamesExist) {
|
if (liveGamesExist) {
|
||||||
document.getElementById('live-games').innerText = "Live Games"
|
if (!document.getElementById('live-games')) {
|
||||||
|
var targetElement = document.getElementById('live-games-section');
|
||||||
|
var newElement = document.createElement('h1');
|
||||||
|
newElement.setAttribute('id', 'live-games');
|
||||||
|
newElement.innerText = 'Live Games';
|
||||||
|
targetElement.parentNode.insertBefore(newElement, targetElement);
|
||||||
|
}
|
||||||
liveGamesSection.innerHTML = generateGameBoxes(data.live_games, 'LIVE');
|
liveGamesSection.innerHTML = generateGameBoxes(data.live_games, 'LIVE');
|
||||||
|
} else {
|
||||||
|
var liveGamesElement = document.getElementById('live-games');
|
||||||
|
if (liveGamesElement) {
|
||||||
|
liveGamesElement.remove();
|
||||||
|
}
|
||||||
|
liveGamesSection.innerHTML = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preGamesSection) {
|
if (preGamesSection) {
|
||||||
var preGamesExist = data && data.pre_games && data.pre_games.length > 0;
|
var preGamesExist = data && data.pre_games && data.pre_games.length > 0;
|
||||||
if (preGamesExist) {
|
if (preGamesExist) {
|
||||||
document.getElementById('on-later').innerText = "On Later"
|
if (!document.getElementById('on-later')) {
|
||||||
|
var targetElement = document.getElementById('pre-games-section');
|
||||||
|
var newElement = document.createElement('h1');
|
||||||
|
newElement.setAttribute('id', 'on-later');
|
||||||
|
newElement.innerText = 'Scheduled Games';
|
||||||
|
targetElement.parentNode.insertBefore(newElement, targetElement);
|
||||||
|
}
|
||||||
preGamesSection.innerHTML = generateGameBoxes(data.pre_games, 'PRE');
|
preGamesSection.innerHTML = generateGameBoxes(data.pre_games, 'PRE');
|
||||||
|
} else {
|
||||||
|
var onLaterElement = document.getElementById('on-later');
|
||||||
|
if (onLaterElement) {
|
||||||
|
onLaterElement.remove();
|
||||||
|
}
|
||||||
|
preGamesSection.innerHTML = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finalGamesSection) {
|
if (finalGamesSection) {
|
||||||
var finalGamesExist = data && data.final_games && data.final_games.length > 0;
|
var finalGamesExist = data && data.final_games && data.final_games.length > 0;
|
||||||
|
|
||||||
|
// Check if final games exist
|
||||||
if (finalGamesExist) {
|
if (finalGamesExist) {
|
||||||
document.getElementById('game-over').innerText = "Game Over"
|
// Create or update "Game Over" heading
|
||||||
|
if (!document.getElementById('game-over')) {
|
||||||
|
var targetElement = document.getElementById('final-games-section');
|
||||||
|
var newElement = document.createElement('h1');
|
||||||
|
newElement.setAttribute('id', 'game-over');
|
||||||
|
newElement.innerText = 'Game Over';
|
||||||
|
targetElement.parentNode.insertBefore(newElement, targetElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update final games section with generated game boxes
|
||||||
finalGamesSection.innerHTML = generateGameBoxes(data.final_games, 'FINAL');
|
finalGamesSection.innerHTML = generateGameBoxes(data.final_games, 'FINAL');
|
||||||
|
} else {
|
||||||
|
// Remove "Game Over" heading if it exists and clear final games section
|
||||||
|
var gameOverElement = document.getElementById('game-over');
|
||||||
|
if (gameOverElement) {
|
||||||
|
gameOverElement.remove();
|
||||||
|
}
|
||||||
|
finalGamesSection.innerHTML = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ body {
|
|||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-top: 20px;
|
margin-top: 15px;
|
||||||
|
margin-bottom: 25px;
|
||||||
color: #f2f2f2; /* Lighten the text color */
|
color: #f2f2f2; /* Lighten the text color */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +134,7 @@ h1 {
|
|||||||
color: #fff; /* White text color for live state */
|
color: #fff; /* White text color for live state */
|
||||||
font-weight: bolder; /* Bold text for live state */
|
font-weight: bolder; /* Bold text for live state */
|
||||||
z-index: 1; /* Ensure the live state box is above other content */
|
z-index: 1; /* Ensure the live state box is above other content */
|
||||||
|
width: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.live-state-intermission {
|
.live-state-intermission {
|
||||||
@@ -146,6 +148,7 @@ h1 {
|
|||||||
color: #fff; /* White text color for live state */
|
color: #fff; /* White text color for live state */
|
||||||
font-weight: bolder; /* Bold text for live state */
|
font-weight: bolder; /* Bold text for live state */
|
||||||
z-index: 1; /* Ensure the live state box is above other content */
|
z-index: 1; /* Ensure the live state box is above other content */
|
||||||
|
width: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.live-time {
|
.live-time {
|
||||||
@@ -158,18 +161,26 @@ h1 {
|
|||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #ddd; /* Lighter text color for time box */
|
color: #ddd; /* Lighter text color for time box */
|
||||||
z-index: 1; /* Ensure the time box is above other content */
|
z-index: 1; /* Ensure the time box is above other content */
|
||||||
|
width: 30px;
|
||||||
|
display: flex; /* Use flexbox */
|
||||||
|
justify-content: space-evenly; /* Center content horizontally */
|
||||||
|
align-items: center; /* Center content vertically */
|
||||||
}
|
}
|
||||||
|
|
||||||
.live-time-intermission {
|
.live-time-intermission {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 10px;
|
top: 10px;
|
||||||
left: 60px; /* Adjusted left position */
|
left: 65px; /* Adjusted left position */
|
||||||
background-color: #444; /* Darker background color for time box */
|
background-color: #444; /* Darker background color for time box */
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: #ddd; /* Lighter text color for time box */
|
color: #ddd; /* Lighter text color for time box */
|
||||||
z-index: 1; /* Ensure the time box is above other content */
|
z-index: 1; /* Ensure the time box is above other content */
|
||||||
|
width: 30px;
|
||||||
|
display: flex; /* Use flexbox */
|
||||||
|
justify-content: space-evenly; /* Center content horizontally */
|
||||||
|
align-items: center; /* Center content vertically */
|
||||||
}
|
}
|
||||||
|
|
||||||
#live-games-section {
|
#live-games-section {
|
||||||
@@ -177,7 +188,6 @@ h1 {
|
|||||||
align-items: start;
|
align-items: start;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
margin-top: 20px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pre-games-section {
|
#pre-games-section {
|
||||||
@@ -185,7 +195,6 @@ h1 {
|
|||||||
align-items: start;
|
align-items: start;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
margin-top: 20px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#final-games-section {
|
#final-games-section {
|
||||||
@@ -193,7 +202,6 @@ h1 {
|
|||||||
align-items: start;
|
align-items: start;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
margin-top: 20px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Existing CSS styles */
|
/* Existing CSS styles */
|
||||||
|
|||||||
@@ -6,15 +6,9 @@
|
|||||||
<link rel="stylesheet" type="text/css" href="static\styles.css">
|
<link rel="stylesheet" type="text/css" href="static\styles.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1 id="live-games"></h1>
|
|
||||||
<div id="live-games-section"></div>
|
<div id="live-games-section"></div>
|
||||||
|
|
||||||
<h1 id="on-later"></h1>
|
|
||||||
<div id="pre-games-section"></div>
|
<div id="pre-games-section"></div>
|
||||||
|
|
||||||
<h1 id="game-over"></h1>
|
|
||||||
<div id="final-games-section"></div>
|
<div id="final-games-section"></div>
|
||||||
|
|
||||||
<script src="/static/script.js"></script>
|
<script src="/static/script.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user