Use new config dicts, update function signatures and calls
This commit is contained in:
1 parent
f3939c01dc
commit
39d5853638
1 file changed
+14
-16
@@ -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
|
||||
|
||||
Reference in new issue
Block a user