Change to new util function for table name test, add get_recent_draw_date function
This commit is contained in:
1 parent
52944a53ab
commit
72a1ce6b81
1 file changed
+13
-2
@@ -20,10 +20,21 @@ project_variables = envutil.load_environment_variables()
|
|||||||
|
|
||||||
def get_record_count(table_name: str) -> str | None:
|
def get_record_count(table_name: str) -> str | None:
|
||||||
"""get the most recent draw record from the specified table"""
|
"""get the most recent draw record from the specified table"""
|
||||||
if table_name in ['PowerballDraw', 'MegaMillionsDraw']:
|
if drawutil.check_table_name(table_name):
|
||||||
dal.connect()
|
dal.connect()
|
||||||
session = dal.Session()
|
session = dal.Session()
|
||||||
target_table = Base.registry._class_registry.get(table_name)
|
target_table = Base.registry._class_registry.get(table_name)
|
||||||
return session.query(func.count(target_table.draw_date)).first()[0]
|
return session.query(func.count(target_table.draw_date)).first()[0]
|
||||||
else:
|
else:
|
||||||
raise ValueError('Valid values are PowerballDraw, MegaMillionsDraw')
|
raise ValueError('An invalid table name was specified.')
|
||||||
|
|
||||||
|
|
||||||
|
def get_recent_draw_date(table_name: str) -> datetime | None:
|
||||||
|
"""get the most recent draw date from the specified table"""
|
||||||
|
if drawutil.check_table_name(table_name):
|
||||||
|
dal.connect()
|
||||||
|
session = dal.Session()
|
||||||
|
target_table = Base.registry._class_registry.get(table_name)
|
||||||
|
return session.query(func.max(target_table.draw_date)).first()[0]
|
||||||
|
else:
|
||||||
|
raise ValueError('An invalid table name was specified.')
|
||||||
Reference in new issue
Block a user