diff options
| author | 2020-03-11 16:41:02 +0200 | |
|---|---|---|
| committer | 2020-03-11 16:41:02 +0200 | |
| commit | 4ecacdc6743880749d33891bfa74788dc3bd7852 (patch) | |
| tree | 3011aa67bd174be8cab9765b6089c0468d525453 /bot | |
| parent | (Space Cog): Add base URL parameter to helper function `fetch_from_nasa` (diff) | |
(Space Cog): Created task for `.mars` command rovers fetching one time in day
Diffstat (limited to 'bot')
| -rw-r--r-- | bot/seasons/evergreen/space.py | 15 | 
1 files changed, 15 insertions, 0 deletions
diff --git a/bot/seasons/evergreen/space.py b/bot/seasons/evergreen/space.py index f4faeb48..4684f8f7 100644 --- a/bot/seasons/evergreen/space.py +++ b/bot/seasons/evergreen/space.py @@ -5,6 +5,7 @@ from typing import Any, Dict, Optional, Union  from urllib.parse import urlencode  from discord import Embed +from discord.ext import tasks  from discord.ext.commands import BadArgument, Cog, Context, Converter, group  from bot.bot import SeasonalBot @@ -42,6 +43,20 @@ class Space(Cog):          self.bot = bot          self.http_session = bot.http_session +        self.rovers = {} +        self.get_rovers.start() + +    @tasks.loop(hours=24) +    async def get_rovers(self) -> None: +        """Get listing of rovers from NASA API and info about their start and end dates.""" +        data = await self.fetch_from_nasa("mars-photos/api/v1/rovers", params={"api_key": Tokens.nasa}) + +        for rover in data["rovers"]: +            self.rovers[rover["name"].lower()] = { +                "min_date": rover["landing_date"], +                "max_date": rover["max_date"] +            } +      @group(name="space", invoke_without_command=True)      async def space(self, ctx: Context) -> None:          """Head command that contains commands about space."""  |