source dates from DB
This commit is contained in:
@@ -4,8 +4,6 @@ import typing
|
||||
|
||||
import peewee
|
||||
|
||||
import wordlinator.utils
|
||||
|
||||
db = peewee.PostgresqlDatabase(
|
||||
os.getenv("DB_NAME", "wordlegolf"),
|
||||
user=os.getenv("DB_USER", "wordlegolf"),
|
||||
@@ -117,10 +115,11 @@ class WordleDb:
|
||||
try:
|
||||
return Game.get(Game.game == round_no)
|
||||
except peewee.DoesNotExist:
|
||||
start_date = (
|
||||
start_date
|
||||
or wordlinator.utils.WORDLE_GOLF_ROUND_DATES[round_no - 1]
|
||||
)
|
||||
if not start_date:
|
||||
raise ValueError(
|
||||
f"Round {round_no} does not exist, "
|
||||
"and no start_date provide to create it"
|
||||
)
|
||||
return Game.create(game=round_no, start_date=start_date)
|
||||
|
||||
def get_or_create_hole(self, round_no, hole_no):
|
||||
|
||||
@@ -3,13 +3,11 @@ import dataclasses
|
||||
import datetime
|
||||
import typing
|
||||
|
||||
import wordlinator.db.pg
|
||||
|
||||
WORDLE_DAY_ZERO = datetime.date(2021, 6, 19)
|
||||
|
||||
WORDLE_GOLF_ROUND_DATES = [
|
||||
datetime.date(2022, 5, 9),
|
||||
datetime.date(2022, 5, 31),
|
||||
datetime.date(2022, 6, 24),
|
||||
]
|
||||
WORDLE_GOLF_ROUNDS = wordlinator.db.pg.WordleDb().get_rounds()
|
||||
|
||||
|
||||
def date_from_string(datestr: str):
|
||||
@@ -27,10 +25,10 @@ class GolfHole:
|
||||
|
||||
@classmethod
|
||||
def from_date(cls, date: datetime.date):
|
||||
for game_no, start_date in enumerate(WORDLE_GOLF_ROUND_DATES, start=1):
|
||||
hole_value = (date - start_date).days + 1
|
||||
if 1 <= hole_value <= 18:
|
||||
return cls(game_no=game_no, hole_no=hole_value)
|
||||
for round in WORDLE_GOLF_ROUNDS:
|
||||
if round.start_date <= date <= round.end_date:
|
||||
hole_no = (date - round.start_date).days + 1
|
||||
return cls(game_no=round.game, hole_no=hole_no)
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user