@@ -33,13 +33,11 @@ def __init__(self) -> None:
3333 self ._last_displayed_day : str | None = None
3434
3535 def fetch (self , * , exit_on_error : bool = True ) -> None :
36- """Fetch astronomical data and display if it is new day's data ."""
36+ """Fetch astronomical data and display if not already displayed today ."""
3737 lat = weather_settings .LOCATION .latitude
3838 lon = weather_settings .LOCATION .longitude
3939 logger .info (f"Using latitude={ lat } longitude={ lon } " )
40-
4140 start = time .time ()
42-
4341 try :
4442 astro = fetch_astronomical_data_from_api (lat , lon )
4543 FETCH_COUNTER .inc ()
@@ -54,15 +52,16 @@ def fetch(self, *, exit_on_error: bool = True) -> None:
5452 return
5553 finally :
5654 FETCH_DURATION .observe (time .time () - start )
57-
58- # Only display once per day
5955 today_str = date .today ().isoformat ()
6056 if self ._last_displayed_day != today_str :
6157 display_astronomical_data (astro )
6258 self ._last_displayed_day = today_str
6359
60+ def reset_display (self ):
61+ """Reset the last displayed day so display will occur again."""
62+ self ._last_displayed_day = None
63+
6464 def _handle_fetch_error (self , exc : Exception , exit_on_error : bool ) -> None :
65- """Handle errors during the fetch operation."""
6665 FETCH_ERRORS .inc ()
6766 if isinstance (exc , httpx .HTTPStatusError ):
6867 logger .error ("HTTP status error: %s" , exc )
@@ -74,10 +73,8 @@ def _handle_fetch_error(self, exc: Exception, exit_on_error: bool) -> None:
7473 logger .error ("JSON decode error: %s" , exc )
7574 else :
7675 logger .exception ("Unexpected error" )
77-
7876 if exit_on_error :
7977 raise SystemExit (1 ) from exc
80-
8178 raise AppError (str (exc )) from exc
8279
8380
0 commit comments