aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/seasons/evergreen/space.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/bot/seasons/evergreen/space.py b/bot/seasons/evergreen/space.py
index 670da791..664f9972 100644
--- a/bot/seasons/evergreen/space.py
+++ b/bot/seasons/evergreen/space.py
@@ -1,5 +1,4 @@
import logging
-import textwrap
from datetime import datetime
from random import randint
from typing import Any, Dict, Optional
@@ -14,9 +13,9 @@ from bot.constants import Tokens
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/"
+BASE_URL = "https://api.nasa.gov"
+NASA_IMAGES_BASE = "https://images-api.nasa.gov"
+EPIC_BASE_URL = "https://epic.gsfc.nasa.gov"
# Default Parameters:
# .apod command default request parameters
@@ -66,11 +65,11 @@ class Space(Cog):
"media_type": "image",
"page": page
}
- async with self.http_session.get(url=f"{NASA_IMAGES_BASE}search?{urlencode(params)}") as resp:
+ async with self.http_session.get(url=f"{NASA_IMAGES_BASE}/search?{urlencode(params)}") as resp:
data = await resp.json()
# Get (random) item from result, that will be shown
- item = data["collection"]["item"][randint(0, len(data["collection"]["item"]) - 1)]
+ item = data["collection"]["items"][randint(0, len(data["collection"]["items"]) - 1)]
# Create embed and send it
embed = Embed(title=item["data"][0]["title"], description=item["data"][0]["description"])
@@ -83,7 +82,7 @@ class Space(Cog):
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:
+ 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
@@ -92,7 +91,7 @@ class Space(Cog):
# 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"
+ 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"])
@@ -122,8 +121,12 @@ class Space(Cog):
# Check for empty result
if len(result["photos"]) < 1:
- await ctx.send(textwrap.dedent(f"""We can't find result in date {date}.
- **Note:** Current dates must in range 2012-08-06 and 2019-09-28."""))
+ err_msg = (
+ f"We can't find result in date {date}. "
+ "**Note:** Current dates must in range 2012-08-06 and 2019-09-28."
+ )
+ await ctx.send(err_msg)
+ return
# Get random item from result, generate embed with it and send
item = result["photos"][randint(0, len(result["photos"]) - 1)]
@@ -137,7 +140,7 @@ class Space(Cog):
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
- async with self.http_session.get(url=f"{BASE_URL}{endpoint}?{urlencode(params)}") as resp:
+ async with self.http_session.get(url=f"{BASE_URL}/{endpoint}?{urlencode(params)}") as resp:
return await resp.json()