dnd-calendar/reckoning/calendar.py

95 lines
2.5 KiB
Python
Raw Normal View History

2023-08-20 12:01:12 -07:00
"""
A Telisaran calendaring tool.
"""
from . import telisaran
2023-08-20 17:00:42 -07:00
from rich import print
2023-08-20 12:01:12 -07:00
from rich.table import Table
2023-08-20 17:00:42 -07:00
from rich.columns import Columns
from rich.panel import Panel
2023-08-20 12:01:12 -07:00
class TelisaranCalendar:
"""
The Telisaran Calendar
Syfdag kindle fates first light
Mimdag have a secret might
Wodag have the strength to fight
Thordag curse the wrong, avenge the right
Freydag love fair beautys sight
Dwarven nursery rhyme
"""
def __init__(self, today=None, start=None, end=None):
self.today = today
if not self.today:
self.today = telisaran.today
self._end = end or self.today
if start:
self._start = start
else:
self._start = telisaran.datetime(
year=self._end.year.year,
season=self._end.season.season_of_year,
day=1
)
2023-08-20 17:00:42 -07:00
def _season(self, season, long=False):
if long:
headers = season.day_names
title = f"Season of the {season.name}, Year {season.year}"
else:
headers = [n[0:2] for n in season.day_names]
title = season.name.upper()
table = Table(*headers, title=title)
2023-08-20 12:01:12 -07:00
row = []
2023-08-20 17:00:42 -07:00
for day in season.days:
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}")
2023-08-20 12:01:12 -07:00
if day.day_of_span == telisaran.Span.length_in_days:
table.add_row(*row)
row = []
return table
2023-08-20 17:00:42 -07:00
@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)
2023-08-20 12:01:12 -07:00
@property
def yesterday(self):
try:
return self.today - telisaran.Day.length_in_seconds
except telisaran.InvalidDayError:
return "Mortals cannot go back before the beginning of time."
@property
def tomorrow(self):
return self.today + telisaran.Day.length_in_seconds
def __repr__(self):
return "The Telisaran Calendar"
2023-08-20 17:00:42 -07:00
def main():
print(TelisaranCalendar().calendar)
print(TelisaranCalendar().season)
if __name__ == '__main__':
main()