46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
"""
|
|
util/drawing.py
|
|
|
|
Utility functions for drawing data processing
|
|
"""
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
def get_next_draw_date(game: str | None, from_date: str | None = None) -> str | None:
|
|
"""
|
|
Gets the next drawing date from the current or specified date for the given game
|
|
If the current date is the next drawing date, the current date is returned
|
|
|
|
:param game: megamillions or powerball
|
|
:param from_date: date to get next drawing date from, if omitted the current date is used
|
|
:return: next drawing date
|
|
|
|
Examples:
|
|
>>> get_next_draw_date(game='mega-millions', from_date='02/15/2026')
|
|
'02/17/2026'
|
|
>>> get_next_draw_date(game='powerball', from_date='02/15/2026')
|
|
'02/16/2026'
|
|
"""
|
|
target_days = {
|
|
"powerball": [0, 2, 5],
|
|
"mega-millions": [1, 4]
|
|
}
|
|
|
|
return_date = None
|
|
return_date_format = '%m/%d/%Y'
|
|
|
|
# if a valid game is not specified, return None
|
|
if game is None or game not in target_days.keys():
|
|
return return_date
|
|
|
|
# if no date was specified, use today's date
|
|
if from_date is None:
|
|
return_date = datetime.today()
|
|
else:
|
|
return_date = datetime.strptime(from_date, return_date_format)
|
|
|
|
while return_date.weekday() not in target_days[game]:
|
|
return_date += timedelta(days=1)
|
|
|
|
return return_date.strftime(return_date_format)
|