From 2543036ddd9ae900b4d868a883d97b1504051ae0 Mon Sep 17 00:00:00 2001 From: Josh Wright Date: Sun, 18 Feb 2024 22:40:01 -0500 Subject: [PATCH 1/2] update .gitignore: add nhl standings and remove from repo --- .gitignore | 3 ++- nhl_standings.db | Bin 8192 -> 0 bytes 2 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 nhl_standings.db diff --git a/.gitignore b/.gitignore index b191cc5..7754e9c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /nhle_scoreboard_response.txt -/nhle_standings_response.txt \ No newline at end of file +/nhle_standings_response.txt +/nhl_standings.db \ No newline at end of file diff --git a/nhl_standings.db b/nhl_standings.db deleted file mode 100644 index 36f4ed15a0be2e6b171d24aa83f50a2ce483ad41..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8192 zcmeI#KW`H;7zXfj>NdU0#ZJ=vX_BTf0tA&1BESw!8%oCL^^O)VTG8RJC zUB)cSvh|hF*J(rg2A_8Hzv=(4+17P=oYpBs+m`-80|5{K0T2KI5C8!X009sH0T2Lz zb1(3sfs&jT?Uj&x$RXvpFL1X

e0uvNpI6Dv_ft2gM1@j$S3lFyeDtTYx0~##3NmDhukEWbOC4}00JNY z0w4eaAOHd&00JNY0_RL1!|(-!ngRDlL;h@}7<22mj8J#TqminoQ;WES(CWk+sl{Th zhA*4&M6eA#LBy(7BMZ2u<3jQ{jMRdguHq^}E8$TX3stSVm6K|GFA}Pfp=DgxgIw~y zFQh70$-J4p!VmnI2Wo!NEt&YeKp%uvsp1rI0ihi~=oe>6!6dhZ987$v3VAnglA949 z37Ma#bEfciB>E@Im|LJZ^I%;C`cy6=l`FehlV25wexR}inlZy2(Pum6%$}hsYW8Wi zrs!0Pn9imdAz3$VCT{tGE|X4XU3?Lt2mBxqtS$Jya#L>V*P4%XAT>uFQ@QOAhOyKI z94BKN;ro*)@;xqvvhDmVUP5Rs4EjQ{O=+TPcG^jr&2DJaWQoq0BFl$dFW(!AnOu6> wsCKv<=$A~-I9M;x?#4V)*qt)3Z$^e?ijc$!6PNK&Cld)5;i_%K%@@Q!0R!^5TmS$7 From 0412b07f35b3d3859d6e1f4309d324dc09fca5d1 Mon Sep 17 00:00:00 2001 From: Josh Wright Date: Sun, 18 Feb 2024 22:40:51 -0500 Subject: [PATCH 2/2] app.py: add update_nhl_standings function and set to run every 5 min --- app.py | 12 ++++++------ update_nhl_standings_db.py | 27 ++++++++++++++------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app.py b/app.py index 477344d..9aa4a30 100644 --- a/app.py +++ b/app.py @@ -7,6 +7,7 @@ import threading import time import schedule import json +from update_nhl_standings_db import update_nhl_standings app = Flask(__name__) @@ -39,8 +40,9 @@ def store_scoreboard_data(): global scoreboard_data scoreboard_data = get_nhle_scoreboard() -# Schedule the task to run every 10 seconds -def schedule_task(): +# Schedule tasks +def schedule_tasks(): + schedule.every(300).seconds.do(update_nhl_standings) schedule.every(10).seconds.do(store_scoreboard_data) while True: schedule.run_pending() @@ -157,9 +159,6 @@ def get_game_outcome(game_state, game): return last_period_type - - - def calculate_game_priority(game): if game["gameState"] in ["FINAL", "OFF", "PRE", "FUT"] or game["clock"]["inIntermission"]: return 0 @@ -250,5 +249,6 @@ def get_scoreboard(): if __name__ == '__main__': store_scoreboard_data() - threading.Thread(target=schedule_task).start() + update_nhl_standings() + threading.Thread(target=schedule_tasks).start() serve(app, host="0.0.0.0", port=2897) \ No newline at end of file diff --git a/update_nhl_standings_db.py b/update_nhl_standings_db.py index 5f5319b..45e9120 100644 --- a/update_nhl_standings_db.py +++ b/update_nhl_standings_db.py @@ -44,21 +44,22 @@ def extract_standings_info(): print("Error:", response.status_code) return None -# Connect to SQLite database -conn = sqlite3.connect("nhl_standings.db") +def update_nhl_standings(): + # Connect to SQLite database + conn = sqlite3.connect("nhl_standings.db") -# Create standings table if it doesn't exist -create_standings_table(conn) + # Create standings table if it doesn't exist + create_standings_table(conn) -# Truncate standings table before inserting new data -truncate_standings_table(conn) + # Truncate standings table before inserting new data + truncate_standings_table(conn) -# Extract standings info -standings_info = extract_standings_info() + # Extract standings info + standings_info = extract_standings_info() -# Insert standings info into the database -if standings_info: - insert_standings_info(conn, standings_info) + # Insert standings info into the database + if standings_info: + insert_standings_info(conn, standings_info) -# Close database connection -conn.close() + # Close database connection + conn.close()