from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta, MO, TU, WE, FR, SA 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='megamillions', 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], "megamillions": [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: from_date = datetime.today() else: from_date = datetime.strptime(from_date, return_date_format) while from_date.weekday() not in target_days[game]: from_date += timedelta(days=1) return from_date.strftime(return_date_format)