11"""Handles formatting and displaying astronomical data using rich and pyfiglet."""
22
3+ from datetime import datetime
4+
35from pyfiglet import Figlet
6+ from rich .align import Align
47from rich .console import Console
8+ from rich .panel import Panel
9+ from rich .table import Table
10+ from rich .text import Text
511
612from sample_python_app .core .config import settings
713from sample_python_app .core .logging import setup_logger
@@ -19,16 +25,107 @@ def display_astronomical_data(astro):
1925 """
2026 logger = setup_logger (mode = "silent" )
2127 console = Console ()
22- header = Figlet (font = "small" , width = 100 ).renderText ("Astronomical Data" )
23- logger .info ("Displaying Astronomical Data header." )
24- console .print (f"[bold magenta]{ header } [/bold magenta]" )
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+
2535 sunrise_local = astro .sunrise .astimezone (settings .tz )
36+ sunset_local = astro .sunset .astimezone (settings .tz )
2637 date_art = Figlet (font = "mini" , width = 150 ).renderText (
2738 sunrise_local .strftime ("%A, %B %d, %Y" )
2839 )
29- logger .info (f'Displaying date: { sunrise_local .strftime ("%A, %B %d, %Y" )} ' )
30- console .print (f"[bold cyan]{ date_art } [/bold cyan]" )
31- for name , value in astro .formatted (settings .tz , settings .DATE_FORMAT ).items ():
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+ from rich .table import Table
72+
73+ astro_table = Table (show_header = True , header_style = "bold magenta" , box = None )
74+ astro_table .add_column ("Event" , style = "bold #ff00cc" )
75+ astro_table .add_column ("Local Time" , style = "bold #00eaff" )
76+ tz = settings .tz
77+ time_fmt = "%I:%M:%S %p %Z"
78+ # Color mapping for event types
79+ event_colors = {
80+ "sunrise" : "#ffe066" , # yellow
81+ "sunset" : "#5dade2" , # blue
82+ "transit" : "#ffb347" , # orange
83+ "civil twilight begin" : "#f7cac9" , # pink
84+ "civil twilight end" : "#92a8d1" , # light blue
85+ "nautical twilight begin" : "#f9d423" , # gold
86+ "nautical twilight end" : "#6a89cc" , # purple-blue
87+ "astronomical twilight begin" : "#b388ff" , # violet
88+ "astronomical twilight end" : "#2e86c1" , # deep blue
89+ }
90+ for name , dt in astro .as_local (tz ).items ():
3291 label = name .replace ("_" , " " ).title ()
92+ if isinstance (dt , datetime ):
93+ value = dt .strftime (time_fmt )
94+ else :
95+ value = str (dt )
3396 logger .info (f"Displaying { label } : { value } " )
34- console .print (f"[bold cyan]{ label } : [white]{ value } [/white]" )
97+ # Pick color based on event type
98+ color = event_colors .get (label .lower (), "#e17055" ) # fallback: coral
99+ astro_table .add_row (
100+ f"[{ color } ]{ label } [/{ color } ]" , f"[{ color } ]{ value } [/{ color } ]"
101+ )
102+
103+ # Compose all parts into a single renderable for the panel
104+ from rich .console import Group
105+
106+ from rich .columns import Columns
107+
108+ # Combine sunrise and sunset figlet art and times in the same row
109+ sun_figlet_row = Columns (
110+ [
111+ Group (Align .center (sun_text ), Align .center (sunrise_time_text )),
112+ Group (Align .center (sun_set_text ), Align .center (sunset_time_text )),
113+ ],
114+ align = "center" ,
115+ expand = True ,
116+ )
117+
118+ panel_content = Group (
119+ Align .center (header_text ),
120+ Align .center (date_text ),
121+ sun_figlet_row ,
122+ Align .center (astro_table ),
123+ )
124+ console .print (
125+ Panel (
126+ panel_content ,
127+ title = "[bold #ff6ec7]Synthwave Astronomical Events[/bold #ff6ec7]" ,
128+ border_style = "#ff00cc" ,
129+ padding = (1 , 2 ),
130+ )
131+ )
0 commit comments