aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Karlis. S <[email protected]>2020-02-29 16:35:12 +0200
committerGravatar Karlis. S <[email protected]>2020-02-29 16:35:12 +0200
commit2d82c3548d373d7e5daa8a7a005513e79bf2abe5 (patch)
treee605363d84d0e7ab20f7f45ae6c703809c9250c2
parent(Space Cog): Added .nasa command that show information and facts about NASA a... (diff)
(Space Cog): Added .earth command, created new base URL: NASA Epic API base URL
-rw-r--r--bot/seasons/evergreen/space.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/bot/seasons/evergreen/space.py b/bot/seasons/evergreen/space.py
index 5eeba7dc..5b19387c 100644
--- a/bot/seasons/evergreen/space.py
+++ b/bot/seasons/evergreen/space.py
@@ -15,6 +15,7 @@ logger = logging.getLogger(__name__)
# NASA API base URL
BASE_URL = "https://api.nasa.gov/"
NASA_IMAGES_BASE = "https://images-api.nasa.gov/"
+EPIC_BASE_URL = "https://epic.osfc.nasa.gov/"
# Default Parameters:
# .apod command default request parameters
@@ -77,6 +78,28 @@ class Space(Cog):
await ctx.send(embed=embed)
+ @command(name="earth")
+ async def earth(self, ctx: Context) -> None:
+ """Get one of latest random image of earth from NASA API."""
+ # Generate URL and make request to API
+ async with self.http_session.get(url=f"{EPIC_BASE_URL}api/natural") as resp:
+ data = await resp.json()
+
+ # Get random item from result that will be shown
+ item = data[randint(0, len(data) - 1)]
+
+ # Split date for image URL
+ year, month, day = item["date"].split(" ")[0].split("-")
+
+ image_url = f"{EPIC_BASE_URL}archive/natural/{year}/{month}/{day}/jpg/{item['image']}.jpg"
+
+ # Create embed, fill and send it
+ embed = Embed(title="Earth Image", description=item["caption"])
+ embed.set_image(url=image_url)
+ embed.set_footer(text=f"Identifier: {item['identifier']} \u2022 Powered by NASA API")
+
+ await ctx.send(embed=embed)
+
async def fetch_from_nasa(self, endpoint: str, params: Dict[str, Any]) -> Dict[str, Any]:
"""Fetch information from NASA API, return result."""
# Generate request URL from base URL, endpoint and parsed params