From 39d58536389275e18ccea8c21d8b91e350a8c398 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 26 May 2026 19:31:28 -0400 Subject: [PATCH] Use new config dicts, update function signatures and calls --- lottery_predictor/collect.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/lottery_predictor/collect.py b/lottery_predictor/collect.py index b6da7d7..55fd316 100644 --- a/lottery_predictor/collect.py +++ b/lottery_predictor/collect.py @@ -10,20 +10,18 @@ from sqlalchemy import func from sqlalchemy.exc import IntegrityError from data.database import Base, dal +from lottery_predictor.config import GAME_INFO, PROJECT_VARIABLES import util.drawing as drawutil -import util.environment as envutil import util.scrape as scrapeutil -project_variables = envutil.load_environment_variables() - -def get_record_count(table_name: str) -> int | None: +def get_record_count(game: str) -> int | None: """ - :param table_name: the name of the table to get a count of records from + :param game: the name of the game to get a count of records for :returns: the count of records found in the specified table """ - game_dict = drawutil.check_table_name(table_name=table_name) + game_dict = GAME_INFO[game] if game_dict: dal.connect() session = dal.Session() @@ -33,13 +31,13 @@ def get_record_count(table_name: str) -> int | None: raise ValueError('An invalid table name was specified.') -def get_recent_draw_date(table_name: str) -> datetime | None: +def get_recent_draw_date(game: str) -> datetime | None: """ - :param table_name: the name of the table to get the most recent draw date from + :param game: the name of the game to get a recent draw date for :returns datetime: the most recent draw date, if there is one """ - game_dict = drawutil.check_table_name(table_name=table_name) + game_dict = GAME_INFO[game] if game_dict: dal.connect() session = dal.Session() @@ -49,27 +47,27 @@ def get_recent_draw_date(table_name: str) -> datetime | None: raise ValueError('An invalid table name was specified.') -def get_missing_records(table_name: str) -> int: +def get_missing_records(game: str) -> int: """ - :param table_name: the name of the table to collect and insert missing records in + :param game: the name of the game to get missing records for :returns: the number of records inserted into the target table """ - # if the table_name is valid - game_dict = drawutil.check_table_name(table_name=table_name) + # if the game is valid + game_dict = GAME_INFO[game] if game_dict: insert_count = 0 # connect to the database and establish a session dal.connect() session = dal.Session() - date_format = project_variables['LP_DATE_PASS_FORMAT'] + date_format = PROJECT_VARIABLES['LP_DATE_PASS_FORMAT'] target_table = Base.metadata.tables.get(game_dict['db_table_name']) - record_count = get_record_count(table_name=table_name) + record_count = get_record_count(game=game) target_game = game_dict['game_name'] end_year = datetime.today().year + 1 - recent_draw_date = (get_recent_draw_date(table_name=table_name) + timedelta(days=1)).strftime(date_format) + recent_draw_date = (get_recent_draw_date(game=game) + timedelta(days=1)).strftime(date_format) following_draw_date = datetime.strptime(drawutil.get_next_draw_date(game=target_game, from_date=recent_draw_date), date_format) start_year = game_dict['inception_year'] if record_count == 0 else following_draw_date.year