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