aboutsummaryrefslogtreecommitdiffstats
path: root/bot/seasons/evergreen/space.py
diff options
context:
space:
mode:
authorGravatar Karlis. S <[email protected]>2020-02-29 13:23:26 +0200
committerGravatar Karlis. S <[email protected]>2020-02-29 13:23:26 +0200
commit1575b79fbf9c27fc0d48b5cad2fa8131b74504cb (patch)
tree8415f0dcb868bd9ee31e9de5302c89cd26cd1614 /bot/seasons/evergreen/space.py
parent(Space Cog): Created .apod command that support date parameter. (diff)
(Space Cog): Created get_random_nasa_item function what will be used in (upcoming) .nasa command.
Diffstat (limited to 'bot/seasons/evergreen/space.py')
-rw-r--r--bot/seasons/evergreen/space.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/bot/seasons/evergreen/space.py b/bot/seasons/evergreen/space.py
index 2caeb6df..2dd17ecf 100644
--- a/bot/seasons/evergreen/space.py
+++ b/bot/seasons/evergreen/space.py
@@ -1,5 +1,6 @@
import logging
from datetime import datetime
+from random import randint
from typing import Any, Dict, Optional
from urllib.parse import urlencode
@@ -58,6 +59,16 @@ class Space(Cog):
async with self.http_session.get(url=f"{BASE_URL}{endpoint}?{urlencode(params)}") as resp:
return await resp.json()
+ async def get_random_nasa_item(self, data: Dict[str, Any]) -> Dict[str, Any]:
+ """Get random item from Dictionary that is fetched from NASA API in .nasa command."""
+ # Get how much items is available
+ length = len(data["collection"]["items"])
+
+ # Get position of item that will be returned
+ pos = randint(0, length - 1)
+
+ return data["collection"]["items"][pos]
+
def setup(bot: SeasonalBot) -> None:
"""Load Space Cog."""