1616from sample_python_app .exceptions import AppError
1717from sample_python_app .services import (
1818 CustomHTTPClient ,
19- fetch_astronomical_data_from_api ,
2019 fetch_hourly_forecast_from_api ,
20+ fetch_weather_point_data ,
2121 set_next_hour_forecast_temperature ,
2222)
2323from sample_python_app .ui import display_astronomical_data
2424
2525
26+ def extract_astronomical_data (weather_point_data ):
27+ """Extract the astronomical data from a WeatherPointDataFeature object."""
28+ if hasattr (weather_point_data , "properties" ) and hasattr (
29+ weather_point_data .properties , "astronomical_data"
30+ ):
31+ return weather_point_data .properties .astronomical_data
32+ raise AttributeError ("Input does not have properties.astronomical_data" )
33+
34+
2635class AstroFetcher :
2736 """Fetches astronomical data and displays only once per day.
2837
@@ -45,7 +54,7 @@ def fetch(self, *, exit_on_error: bool = True) -> None:
4554 start = time .time ()
4655
4756 try :
48- astro = fetch_astronomical_data_from_api (lat , lon , client = self .client )
57+ weather_point_data = fetch_weather_point_data (lat , lon , client = self .client )
4958 forecast = fetch_hourly_forecast_from_api (lat , lon , client = self .client )
5059 set_next_hour_forecast_temperature (forecast , location = f"{ lat } ,{ lon } " )
5160 FETCH_COUNTER .inc ()
@@ -60,7 +69,8 @@ def fetch(self, *, exit_on_error: bool = True) -> None:
6069 today = date .today ().isoformat ()
6170
6271 if self ._last_displayed_day != today :
63- display_astronomical_data (astro , forecast )
72+ astro_data = extract_astronomical_data (weather_point_data )
73+ display_astronomical_data (astro_data , forecast )
6474 self ._last_displayed_day = today
6575
6676 def reset_display (self ):
@@ -91,9 +101,6 @@ def shutdown_runner() -> None:
91101 """Shutdown helper to close long-lived resources owned by the runner.
92102
93103 Call this from application shutdown hooks to ensure the HTTP client is
94- properly closed and connections are released.
104+ properly closed and resources are released.
95105 """
96- try :
97- fetcher .close ()
98- except Exception :
99- logger .exception ("Error during runner shutdown" )
106+ fetcher .close ()
0 commit comments