Better calendar output

This commit is contained in:
evilchili 2023-08-20 17:00:42 -07:00
parent d176ac16ad
commit 9ca49f7b90
3 changed files with 55 additions and 15 deletions

View File

@ -39,3 +39,7 @@ remove-unused-variables = true # remove unused variables
[build-system] [build-system]
requires = ["poetry-core>=1.0.0"] requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api" build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts]
telisar_calendar = "reckoning.calendar:main"

View File

@ -3,7 +3,10 @@ A Telisaran calendaring tool.
""" """
from . import telisaran from . import telisaran
from rich import print
from rich.table import Table from rich.table import Table
from rich.columns import Columns
from rich.panel import Panel
class TelisaranCalendar: class TelisaranCalendar:
@ -36,20 +39,37 @@ class TelisaranCalendar:
day=1 day=1
) )
@property def _season(self, season, long=False):
def season(self): if long:
table = Table( headers = season.day_names
*[n[0:2] for n in telisaran.Day.names], title = f"Season of the {season.name}, Year {season.year}"
title=self._start.season.name.upper() else:
) headers = [n[0:2] for n in season.day_names]
title = season.name.upper()
table = Table(*headers, title=title)
row = [] row = []
for day in self._start.season.days: for day in season.days:
row.append("{:02d}".format(day.day_of_season)) if season == self.today.season and day.day_of_season == self.today.day.number:
row.append(f"[bold]{day.day_of_season:02d}[/bold]")
else:
row.append(f"{day.day_of_season:02d}")
if day.day_of_span == telisaran.Span.length_in_days: if day.day_of_span == telisaran.Span.length_in_days:
table.add_row(*row) table.add_row(*row)
row = [] row = []
return table return table
@property
def season(self):
return self._season(self._start.season, long=True)
@property
def calendar(self):
return Panel(Columns(
[self._season(season) for season in telisaran.today.year.seasons],
equal=True,
expand=True,
), title="The Telisaran Calendar", highlight=True, width=120)
@property @property
def yesterday(self): def yesterday(self):
try: try:
@ -63,3 +83,12 @@ class TelisaranCalendar:
def __repr__(self): def __repr__(self):
return "The Telisaran Calendar" return "The Telisaran Calendar"
def main():
print(TelisaranCalendar().calendar)
print(TelisaranCalendar().season)
if __name__ == '__main__':
main()

View File

@ -487,6 +487,7 @@ class Season(DateObject):
year (int): The year in which this season falls. year (int): The year in which this season falls.
""" """
names = ['Fox', 'Owl', 'Wolf', 'Eagle', 'Shark', 'Lion', 'Raven', 'Bear'] names = ['Fox', 'Owl', 'Wolf', 'Eagle', 'Shark', 'Lion', 'Raven', 'Bear']
day_names = Day.names
length_in_spans = 9 length_in_spans = 9
length_in_days = length_in_spans * Span.length_in_days length_in_days = length_in_spans * Span.length_in_days
length_in_seconds = length_in_days * Day.length_in_seconds length_in_seconds = length_in_days * Day.length_in_seconds
@ -522,6 +523,16 @@ class Season(DateObject):
return "Season of the {}".format(self.name) return "Season of the {}".format(self.name)
class HuntDay(Day):
names = [
"Syf's Hunt",
"Mimir's Hunt",
"Woden's Hunt",
"Thorus's Hunt",
"Freya's Hunt"
]
class FestivalOfTheHunt(Season): class FestivalOfTheHunt(Season):
""" """
The 9th season, which only has 5 days, occurring at the end of each year. The 9th season, which only has 5 days, occurring at the end of each year.
@ -538,13 +549,7 @@ class FestivalOfTheHunt(Season):
name (str): The name of this special season name (str): The name of this special season
year (Year): The year in which this festival falls year (Year): The year in which this festival falls
""" """
day_names = [ day_names = HuntDay.names
"Syf's Hunt",
"Mimir's Hunt",
"Woden's Hunt",
"Thorus's Hunt",
"Freya's Hunt"
]
length_in_spans = 1 length_in_spans = 1
length_in_days = 5 length_in_days = 5
length_in_seconds = length_in_days * Day.length_in_seconds length_in_seconds = length_in_days * Day.length_in_seconds
@ -553,6 +558,8 @@ class FestivalOfTheHunt(Season):
self.season_of_year = 9 self.season_of_year = 9
self.year = year self.year = year
self._days = [] self._days = []
for i in range(1, self.length_in_days + 1):
self._days.append(HuntDay(i, season=self))
@property @property
def name(self): def name(self):