refactor: rename functions across codebase for clarity
This commit is contained in:
@@ -26,9 +26,9 @@ def truncate_standings_table(conn):
|
||||
conn.commit()
|
||||
|
||||
|
||||
def insert_standings_info(conn, standings_info):
|
||||
def insert_standings(conn, standings):
|
||||
cursor = conn.cursor()
|
||||
for team in standings_info:
|
||||
for team in standings:
|
||||
cursor.execute(
|
||||
"""
|
||||
INSERT INTO standings (team_common_name, league_sequence, league_l10_sequence)
|
||||
@@ -43,31 +43,32 @@ def insert_standings_info(conn, standings_info):
|
||||
conn.commit()
|
||||
|
||||
|
||||
def extract_standings_info():
|
||||
def fetch_standings():
|
||||
url = "https://api-web.nhle.com/v1/standings/now"
|
||||
try:
|
||||
response = requests.get(url, timeout=10)
|
||||
response.raise_for_status()
|
||||
standings_data = response.json()
|
||||
standings_info = []
|
||||
standings = []
|
||||
for team in standings_data.get("standings", []):
|
||||
team_info = {
|
||||
"team_common_name": team["teamCommonName"]["default"],
|
||||
"league_sequence": team["leagueSequence"],
|
||||
"league_l10_sequence": team["leagueL10Sequence"],
|
||||
}
|
||||
standings_info.append(team_info)
|
||||
return standings_info
|
||||
standings.append(
|
||||
{
|
||||
"team_common_name": team["teamCommonName"]["default"],
|
||||
"league_sequence": team["leagueSequence"],
|
||||
"league_l10_sequence": team["leagueL10Sequence"],
|
||||
}
|
||||
)
|
||||
return standings
|
||||
except requests.RequestException as e:
|
||||
logger.error("Failed to fetch standings: %s", e)
|
||||
return None
|
||||
|
||||
|
||||
def update_nhl_standings():
|
||||
def refresh_standings():
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
create_standings_table(conn)
|
||||
truncate_standings_table(conn)
|
||||
standings_info = extract_standings_info()
|
||||
if standings_info:
|
||||
insert_standings_info(conn, standings_info)
|
||||
standings = fetch_standings()
|
||||
if standings:
|
||||
insert_standings(conn, standings)
|
||||
conn.close()
|
||||
|
||||
Reference in New Issue
Block a user