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