From 856ee76197befc686970454fe5d7dc6799a0c051 Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Mon, 3 Mar 2025 10:17:59 -0500 Subject: [PATCH 1/3] Add requests checking and retry to solar flare fetch --- get_solar_flare_png.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/get_solar_flare_png.py b/get_solar_flare_png.py index 560e595..72fae26 100755 --- a/get_solar_flare_png.py +++ b/get_solar_flare_png.py @@ -7,6 +7,7 @@ from urllib.parse import urljoin import requests +from ska_helpers import retry URL = "https://www.solen.info/solar/index.html" IMAGE_SRC_PATTERN = r" Path: @@ -55,6 +57,8 @@ def get_last_referenced_web_image( # Fetch the web page and get the html response = requests.get(url) + # Check that the request was successful + response.raise_for_status() html = response.text # get absolute url of the image that matches the supplied pattern @@ -80,6 +84,9 @@ def get_last_referenced_web_image( # Download the new image and save it to the cache directory response = requests.get(img_url) + # Check that the request was successful + response.raise_for_status() + with open(cached_image_file, "wb") as f: f.write(response.content) From ff84a38de484d6465ddc515a676904acb8d608e7 Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Mon, 3 Mar 2025 12:21:06 -0500 Subject: [PATCH 2/3] Print out HTTPError instead of traceback --- get_solar_flare_png.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/get_solar_flare_png.py b/get_solar_flare_png.py index 72fae26..904426c 100755 --- a/get_solar_flare_png.py +++ b/get_solar_flare_png.py @@ -109,6 +109,8 @@ def main(sys_args=None): if __name__ == "__main__": try: main() + except requests.exceptions.HTTPError as e: + print(f"Failed to get page or image: {e}") except Exception: import traceback From 9d8cc3fb600a3592549ebdfb785e9e9d3cbfa58c Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Tue, 4 Mar 2025 12:51:16 -0500 Subject: [PATCH 3/3] Mangle alert words in the retry --- get_solar_flare_png.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/get_solar_flare_png.py b/get_solar_flare_png.py index 904426c..3ec5756 100755 --- a/get_solar_flare_png.py +++ b/get_solar_flare_png.py @@ -24,7 +24,12 @@ def get_options(): return parser -@retry.retry(exceptions=requests.exceptions.RequestException, delay=5, tries=3) +@retry.retry( + exceptions=requests.exceptions.RequestException, + delay=5, + tries=3, + mangle_alert_words=True, +) def get_last_referenced_web_image( url: str, img_src_pattern: str, cache_dir: str | Path ) -> Path: