Skip to content

Commit

Permalink
prevent startup errors from corrupted log
Browse files Browse the repository at this point in the history
Signed-off-by: Clemens Vasters <[email protected]>
  • Loading branch information
clemensv committed Sep 26, 2024
1 parent 0248e52 commit ef465f6
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions noaa/noaa/noaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,19 @@ def load_last_polled_times(self) -> Dict:
Returns:
Dict: The last polled times for each station and product.
"""
if os.path.exists(self.last_polled_file):
with open(self.last_polled_file, 'r', encoding='utf-8') as file:
saved_times: Dict[str, Dict[str, str]] = json.load(file)
last_polled_times: Dict[str, Dict[str, datetime]] = {}
for product, stations in saved_times.items():
for station, timestamp in stations.items():
if product not in last_polled_times:
last_polled_times[product] = {}
last_polled_times[product][station] = datetime.fromisoformat(timestamp)
return last_polled_times
try:
if os.path.exists(self.last_polled_file):
with open(self.last_polled_file, 'r', encoding='utf-8') as file:
saved_times: Dict[str, Dict[str, str]] = json.load(file)
last_polled_times: Dict[str, Dict[str, datetime]] = {}
for product, stations in saved_times.items():
for station, timestamp in stations.items():
if product not in last_polled_times:
last_polled_times[product] = {}
last_polled_times[product][station] = datetime.fromisoformat(timestamp)
return last_polled_times
except Exception as e:
print(f"Error loading last polled times: {e}")
return {}

def save_last_polled_times(self, last_polled_times: Dict):
Expand Down

0 comments on commit ef465f6

Please sign in to comment.