Mercurial > repos > astroteam > analyse_short_astro_text_astro_tool
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a35056104c2c |
---|---|
1 import requests | |
2 import re | |
3 gcn_number = 40274 | |
4 | |
5 | |
6 def fetch_gcn(gcn_number): | |
7 """ | |
8 Fetches the GCN page for the given GCN number and returns the GCN text. | |
9 | |
10 input : gcn_number (int): The GCN number to fetch. | |
11 output : response_text (str): The content of the GCN body. | |
12 If an error occurs, it returns None. | |
13 """ | |
14 | |
15 # URL of the GCN page | |
16 url = 'https://gcn.nasa.gov/circulars/{}.json'.format(gcn_number) | |
17 | |
18 response = requests.get(url) | |
19 | |
20 # Parse JSON | |
21 data = response.json() | |
22 | |
23 # Get the "body" field | |
24 body = data.get("body") | |
25 | |
26 # cleans non-ASCII characters | |
27 cleaned_text = re.sub(r'[^\x00-\x7F]+', '', body) # remove non-ASCII | |
28 print(cleaned_text) | |
29 | |
30 return cleaned_text | |
31 | |
32 | |
33 if __name__ == "__main__": | |
34 fetch_gcn(gcn_number) |