diff options
-rw-r--r-- | bot/seasons/evergreen/space.py | 23 |
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 |