From 27f2465135dc00abb6ec569b050780e9e62d02f3 Mon Sep 17 00:00:00 2001 From: Jaydeep Das Date: Sat, 23 Oct 2021 16:26:26 +0530 Subject: [PATCH] Added new file: nasa_data.py (#5543) * Added new file: nasa_data.py * Modified as per review * Minor change * print(get_archive_data("apollo 2011")["collection"]["items"][0]["data"][0]["description"]) * Update nasa_data.py Co-authored-by: Christian Clauss --- web_programming/nasa_data.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 web_programming/nasa_data.py diff --git a/web_programming/nasa_data.py b/web_programming/nasa_data.py new file mode 100644 index 0000000..9b15c38 --- /dev/null +++ b/web_programming/nasa_data.py @@ -0,0 +1,27 @@ +import requests + + +def get_apod_data(api_key: str) -> dict: + """ + Get the APOD(Astronomical Picture of the day) data + Get the API Key from : https://api.nasa.gov/ + """ + url = "https://api.nasa.gov/planetary/apod/" + return requests.get(url, params={"api_key": api_key}).json() + + +def get_archive_data(query: str) -> dict: + """ + Get the data of a particular query from NASA archives + """ + endpoint = "https://images-api.nasa.gov/search" + return requests.get(endpoint, params={"q": query}).json() + + +if __name__ == "__main__": + print(get_apod_data("YOUR API KEY")) + print( + get_archive_data("apollo 2011")["collection"]["items"][0]["data"][0][ + "description" + ] + ) -- GitLab