|
1 | 1 | """Handles formatting and displaying astronomical data using rich and pyfiglet.""" |
2 | 2 |
|
3 | | -from datetime import datetime |
4 | | - |
5 | | -from pyfiglet import Figlet |
6 | | -from rich.align import Align |
7 | | -from rich.console import Console |
8 | | -from rich.panel import Panel |
9 | | -from rich.table import Table |
10 | | -from rich.text import Text |
11 | | - |
12 | 3 | from sample_python_app.core.config import settings |
13 | | -from sample_python_app.core.logging import setup_logger |
14 | 4 |
|
15 | 5 |
|
16 | 6 | def display_astronomical_data(astro): |
17 | | - """Format and display astronomical data using rich and pyfiglet. |
18 | | -
|
19 | | - Args: |
20 | | - astro: AstronomicalData object containing sunrise, sunset, and formatted values. |
21 | | -
|
22 | | - Returns: |
23 | | - None |
24 | | -
|
25 | | - """ |
26 | | - logger = setup_logger(mode="silent") |
27 | | - console = Console() |
28 | | - # Synthwave color palette (no longer used) |
29 | | - |
30 | | - header = Figlet(font="slant", width=120).renderText("SYNTHWAVE SUNRISE 🌅") |
31 | | - logger.info("Displaying Synthwave Sunrise header.") |
32 | | - header_text = Text(header) |
33 | | - header_text.stylize("bold magenta") |
34 | | - |
35 | | - sunrise_local = astro.sunrise.astimezone(settings.tz) |
36 | | - sunset_local = astro.sunset.astimezone(settings.tz) |
37 | | - date_art = Figlet(font="mini", width=150).renderText( |
38 | | - sunrise_local.strftime("%A, %B %d, %Y") |
39 | | - ) |
40 | | - logger.info(f'Displaying date: {sunrise_local.strftime("%A, %B %d, %Y")})') |
41 | | - date_text = Text(date_art) |
42 | | - date_text.stylize("bold cyan") |
43 | | - |
44 | | - # Stylized sunrise/sunset |
45 | | - sun_art = Figlet(font="starwars", width=120).renderText("SUNRISE") |
46 | | - sun_set_art = Figlet(font="starwars", width=120).renderText("SUNSET") |
47 | | - sun_text = Text(sun_art) |
48 | | - sun_text.stylize("bold yellow") |
49 | | - # Sunrise time as figlet |
50 | | - sunrise_time_art = Figlet(font="big", width=100).renderText( |
51 | | - sunrise_local.strftime("%H:%M:%S") |
52 | | - ) |
53 | | - sunrise_time_text = Text(sunrise_time_art) |
54 | | - sunrise_time_text.stylize("bold yellow") |
55 | | - |
56 | | - sun_set_text = Text(sun_set_art) |
57 | | - sun_set_text.stylize("bold blue") |
58 | | - # Sunrise time as figlet with AM/PM |
59 | | - sunrise_time_str = sunrise_local.strftime("%I:%M:%S %p") |
60 | | - sunrise_time_art = Figlet(font="big", width=100).renderText(sunrise_time_str) |
61 | | - sunrise_time_text = Text(sunrise_time_art) |
62 | | - sunrise_time_text.stylize("bold yellow") |
63 | | - |
64 | | - sun_set_text = Text(sun_set_art) |
65 | | - sun_set_text.stylize("bold blue") |
66 | | - # Sunset time as figlet with AM/PM |
67 | | - sunset_time_str = sunset_local.strftime("%I:%M:%S %p") |
68 | | - sunset_time_art = Figlet(font="big", width=100).renderText(sunset_time_str) |
69 | | - sunset_time_text = Text(sunset_time_art) |
70 | | - sunset_time_text.stylize("bold blue") |
71 | | - |
72 | | - astro_table = Table(show_header=True, header_style="bold magenta", box=None) |
73 | | - astro_table.add_column("Event", style="bold #ff00cc") |
74 | | - astro_table.add_column("Local Time", style="bold #00eaff") |
75 | | - tz = settings.tz |
76 | | - time_fmt = "%I:%M:%S %p %Z" |
77 | | - # Color mapping for event types |
78 | | - event_colors = { |
79 | | - "sunrise": "#ffe066", # yellow |
80 | | - "sunset": "#5dade2", # blue |
81 | | - "transit": "#ffb347", # orange |
82 | | - "civil twilight begin": "#f7cac9", # pink |
83 | | - "civil twilight end": "#92a8d1", # light blue |
84 | | - "nautical twilight begin": "#f9d423", # gold |
85 | | - "nautical twilight end": "#6a89cc", # purple-blue |
86 | | - "astronomical twilight begin": "#b388ff", # violet |
87 | | - "astronomical twilight end": "#2e86c1", # deep blue |
88 | | - } |
89 | | - for name, dt in astro.as_local(tz).items(): |
90 | | - label = name.replace("_", " ").title() |
91 | | - if isinstance(dt, datetime): |
92 | | - value = dt.strftime(time_fmt) |
93 | | - else: |
94 | | - value = str(dt) |
95 | | - logger.info(f"Displaying {label}: {value}") |
96 | | - # Pick color based on event type |
97 | | - color = event_colors.get(label.lower(), "#e17055") # fallback: coral |
98 | | - astro_table.add_row( |
99 | | - f"[{color}]{label}[/{color}]", f"[{color}]{value}[/{color}]" |
100 | | - ) |
101 | | - |
102 | | - # Compose all parts into a single renderable for the panel |
103 | | - from rich.columns import Columns |
104 | | - from rich.console import Group |
105 | | - |
106 | | - # Combine sunrise and sunset figlet art and times in the same row |
107 | | - sun_figlet_row = Columns( |
108 | | - [ |
109 | | - Group(Align.center(sun_text), Align.center(sunrise_time_text)), |
110 | | - Group(Align.center(sun_set_text), Align.center(sunset_time_text)), |
111 | | - ], |
112 | | - align="center", |
113 | | - expand=True, |
114 | | - ) |
| 7 | + """Display astronomical data using the synthwave terminal UI.""" |
| 8 | + from sample_python_app.ui.synthwave import synthwave_display |
115 | 9 |
|
116 | | - panel_content = Group( |
117 | | - Align.center(header_text), |
118 | | - Align.center(date_text), |
119 | | - sun_figlet_row, |
120 | | - Align.center(astro_table), |
121 | | - ) |
122 | | - console.print( |
123 | | - Panel( |
124 | | - panel_content, |
125 | | - title="[bold #ff6ec7]Synthwave Astronomical Events[/bold #ff6ec7]", |
126 | | - border_style="#ff00cc", |
127 | | - padding=(1, 2), |
128 | | - ) |
129 | | - ) |
| 10 | + synthwave_display(astro, settings) |
0 commit comments