Skip to content

Commit ef465f6

Browse files
committed
prevent startup errors from corrupted log
Signed-off-by: Clemens Vasters <[email protected]>
1 parent 0248e52 commit ef465f6

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

noaa/noaa/noaa.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,19 @@ def load_last_polled_times(self) -> Dict:
155155
Returns:
156156
Dict: The last polled times for each station and product.
157157
"""
158-
if os.path.exists(self.last_polled_file):
159-
with open(self.last_polled_file, 'r', encoding='utf-8') as file:
160-
saved_times: Dict[str, Dict[str, str]] = json.load(file)
161-
last_polled_times: Dict[str, Dict[str, datetime]] = {}
162-
for product, stations in saved_times.items():
163-
for station, timestamp in stations.items():
164-
if product not in last_polled_times:
165-
last_polled_times[product] = {}
166-
last_polled_times[product][station] = datetime.fromisoformat(timestamp)
167-
return last_polled_times
158+
try:
159+
if os.path.exists(self.last_polled_file):
160+
with open(self.last_polled_file, 'r', encoding='utf-8') as file:
161+
saved_times: Dict[str, Dict[str, str]] = json.load(file)
162+
last_polled_times: Dict[str, Dict[str, datetime]] = {}
163+
for product, stations in saved_times.items():
164+
for station, timestamp in stations.items():
165+
if product not in last_polled_times:
166+
last_polled_times[product] = {}
167+
last_polled_times[product][station] = datetime.fromisoformat(timestamp)
168+
return last_polled_times
169+
except Exception as e:
170+
print(f"Error loading last polled times: {e}")
168171
return {}
169172

170173
def save_last_polled_times(self, last_polled_times: Dict):

0 commit comments

Comments
 (0)