102 lines
4.8 KiB
Python
102 lines
4.8 KiB
Python
import datetime
|
|
from src.api import PrayerTimings
|
|
from src.catalog import catalog
|
|
|
|
|
|
class AthanRenderer:
|
|
"""Renders formatted prayer tables, 24-hour ASCII timeline charts, and live countdown dashboards."""
|
|
|
|
@staticmethod
|
|
def format_countdown(seconds: int) -> str:
|
|
hours = seconds // 3600
|
|
mins = (seconds % 3600) // 60
|
|
secs = seconds % 60
|
|
return f"{hours:02d}h {mins:02d}m {secs:02d}s"
|
|
|
|
@classmethod
|
|
def render_table(cls, timings: PrayerTimings) -> str:
|
|
current_p, next_p, sec_rem = timings.get_current_and_next()
|
|
title = catalog.format("table.title", city=timings.city, country=timings.country)
|
|
|
|
lines = [
|
|
"┌─ " + title + " " + "─" * max(0, 56 - len(title)) + "┐",
|
|
"│" + f" {timings.date_gregorian} | {timings.date_hijri}".ljust(60) + "│",
|
|
"├" + "─" * 60 + "┤",
|
|
f"│ {'Prayer':<20} {'Time':<15} {'Status':<20} │",
|
|
"├" + "─" * 60 + "┤",
|
|
]
|
|
|
|
order = ["Fajr", "Sunrise", "Dhuhr", "Asr", "Maghrib", "Isha"]
|
|
for p in order:
|
|
time_val = timings.timings.get(p, "--:--")
|
|
p_label = catalog.get(f"prayers.{p}", p)
|
|
|
|
if p == next_p:
|
|
status_str = f"{catalog.get('table.status_next')} in {cls.format_countdown(sec_rem)}"
|
|
elif p == current_p:
|
|
status_str = catalog.get("table.status_current")
|
|
else:
|
|
status_str = ""
|
|
|
|
lines.append(f"│ {p_label:<20} {time_val:<15} {status_str:<20} │")
|
|
|
|
lines.append("└" + "─" * 60 + "┘")
|
|
return "\n".join(lines)
|
|
|
|
@classmethod
|
|
def render_timeline_chart(cls, timings: PrayerTimings) -> str:
|
|
now = datetime.datetime.now()
|
|
cur_min = now.hour * 60 + now.minute
|
|
current_p, next_p, sec_rem = timings.get_current_and_next()
|
|
|
|
# 24 hour bar mapping: 24h = 48 chars (1 char = 30 minutes)
|
|
chart_len = 48
|
|
bar = ["─"] * chart_len
|
|
|
|
# Place prayer marks
|
|
order = ["Fajr", "Sunrise", "Dhuhr", "Asr", "Maghrib", "Isha"]
|
|
marks: Dict[int, str] = {}
|
|
for p in order:
|
|
m = timings.get_minutes(timings.timings[p])
|
|
idx = min(chart_len - 1, m // 30)
|
|
bar[idx] = "◆"
|
|
|
|
# Place current time mark
|
|
cur_idx = min(chart_len - 1, cur_min // 30)
|
|
bar[cur_idx] = "█"
|
|
|
|
bar_str = "".join(bar)
|
|
|
|
lines = [
|
|
f"┌─ 24-HOUR PRAYER TIMELINE ({timings.city}) ───────────────────────┐",
|
|
"│ │",
|
|
"│ 00:00 06:00 12:00 18:00 24:00 │",
|
|
f"│ {bar_str} │",
|
|
"│ │",
|
|
f"│ [█] Current Time: {now.strftime('%H:%M:%S')} (Active: {catalog.get(f'prayers.{current_p}', current_p)})".ljust(61) + "│",
|
|
f"│ [◆] Next Prayer : {catalog.get(f'prayers.{next_p}', next_p)} at {timings.timings[next_p]} ({cls.format_countdown(sec_rem)})".ljust(61) + "│",
|
|
"└────────────────────────────────────────────────────────────┘",
|
|
]
|
|
return "\n".join(lines)
|
|
|
|
@classmethod
|
|
def render_live_monitor(cls, timings: PrayerTimings) -> str:
|
|
now = datetime.datetime.now()
|
|
current_p, next_p, sec_rem = timings.get_current_and_next(now)
|
|
countdown_str = cls.format_countdown(sec_rem)
|
|
|
|
lines = [
|
|
"┌─ ATHAN LIVE PRAYER MONITOR & ALARM ──────────────────────── [LIVE] ─┐",
|
|
f"│ Location: {timings.city}, {timings.country} | Current Time: {now.strftime('%H:%M:%S')}".ljust(70) + "│",
|
|
"├" + "─" * 70 + "┤",
|
|
"│ │",
|
|
f"│ NEXT PRAYER : {catalog.get(f'prayers.{next_p}', next_p).upper():<25} AT {timings.timings[next_p]} │",
|
|
f"│ COUNTDOWN : {countdown_str:<40} │",
|
|
"│ │",
|
|
"├" + "─" * 70 + "┤",
|
|
f"│ Fajr: {timings.timings['Fajr']} | Dhuhr: {timings.timings['Dhuhr']} | Asr: {timings.timings['Asr']} | Maghrib: {timings.timings['Maghrib']} | Isha: {timings.timings['Isha']} │",
|
|
"│ │",
|
|
f"└─────────────────────────────────── [ Press 'q' or ESC to Exit ] ─────┘",
|
|
]
|
|
return "\n".join(lines)
|