dnd5-scripts/time/get_campaign_time.py

61 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
get_campaign_time.py — получение текущего игрового времени.
Экспортирует функцию get_campaign_time(debug_description: str) -> str,
которую вызывает тул с фронта без параметров.
Возвращает строку в формате Markdown с текущей датой, часом и списком праздников на неделю.
"""
from time_utils import (
get_campaign_time as get_time,
MONTH_NAMES_RU,
get_week_holidays,
get_holiday,
)
def _format_time(year: int, month: int, day: int, hour: int) -> str:
month_name = MONTH_NAMES_RU.get(month, str(month))
return f"{day} {month_name} {year} DR, {hour:02d}:00"
def _format_holidays_section(year: int, month: int, day: int) -> str:
holidays = get_week_holidays(year, month, day)
if not holidays:
return "📅 **Ближайшие праздники:** нет"
lines = ["📅 **Ближайшие праздники:**"]
for m, d, desc, when in holidays:
month_name = MONTH_NAMES_RU.get(m, str(m))
lines.append(f"- **{when}** ({d} {month_name}): {desc}")
return "\n".join(lines)
def get_campaign_time(debug_description: str) -> str:
current = get_time()
time_str = _format_time(current["year"], current["month"], current["day"], current["hour"])
today_holiday = get_holiday(current["month"], current["day"], current["year"])
today_line = f"🎉 **Сегодня:** {today_holiday}" if today_holiday else ""
holidays_section = _format_holidays_section(
current["year"],
current["month"],
current["day"]
)
result = (
f"### 🕰️ Текущее время\n"
f"**Дата:** {time_str}\n"
)
if today_line:
result += f"{today_line}\n"
result += f"\n{holidays_section}"
return result
if __name__ == "__main__":
import sys
if hasattr(sys.stdout, 'reconfigure'):
sys.stdout.reconfigure(encoding='utf-8')
print(get_campaign_time("тест"))