diff fetch_gcn.py @ 0:a35056104c2c draft default tip

planemo upload for repository https://github.com/esg-epfl-apc/tools-astro/tree/main/tools commit da42ae0d18f550dec7f6d7e29d297e7cf1909df2
author astroteam
date Fri, 13 Jun 2025 13:26:36 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fetch_gcn.py	Fri Jun 13 13:26:36 2025 +0000
@@ -0,0 +1,34 @@
+import requests
+import re
+gcn_number = 40274
+
+
+def fetch_gcn(gcn_number):
+    """
+    Fetches the GCN page for the given GCN number and returns the GCN text.
+
+    input : gcn_number (int): The GCN number to fetch.
+    output : response_text (str): The content of the GCN body.
+    If an error occurs, it returns None.
+    """
+
+    # URL of the GCN page
+    url = 'https://gcn.nasa.gov/circulars/{}.json'.format(gcn_number)
+
+    response = requests.get(url)
+
+    # Parse JSON
+    data = response.json()
+
+    # Get the "body" field
+    body = data.get("body")
+
+    # cleans non-ASCII characters
+    cleaned_text = re.sub(r'[^\x00-\x7F]+', '', body)  # remove non-ASCII
+    print(cleaned_text)
+
+    return cleaned_text
+
+
+if __name__ == "__main__":
+    fetch_gcn(gcn_number)