diff options
author | 2021-03-03 09:32:47 -0600 | |
---|---|---|
committer | 2021-03-03 09:32:47 -0600 | |
commit | 4a0401ddb322fba53e2025a63fdf8d0a52e12076 (patch) | |
tree | 2a0b111ba52986140d70780aaa8103d36a59933a | |
parent | Fix docstrings (diff) |
Update earth_photos.py
-rw-r--r-- | bot/exts/easter/earth_photos.py | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/bot/exts/easter/earth_photos.py b/bot/exts/easter/earth_photos.py index 4c319eaa..52bbaf36 100644 --- a/bot/exts/easter/earth_photos.py +++ b/bot/exts/easter/earth_photos.py @@ -1,13 +1,9 @@ -import logging - +import aiohttp import discord -import requests from discord.ext import commands from bot.constants import Tokens -log = logging.getLogger(__name__) - UnClient_id = Tokens.unsplash_key @@ -21,16 +17,14 @@ class EarthPhotos(commands.Cog): @commands.command(aliases=["earth"]) async def earth_photos(self, ctx: commands.Context) -> None: """Returns a random photo of earth, sourced from Unsplash.""" - photorequest = requests.get("https://api.unsplash.com/photos/random?query=earth&client_id=" + UnClient_id) - photojson = photorequest.json() - photourls = photojson.get('urls') - urltosend = photourls.get('regular') - userjson = photojson.get('user') - username = userjson.get('name') - embed = discord.Embed(title="Earth Photo", description="A photo of Earth from Unsplash.", color=0x66ff00) - embed.set_image(url=urltosend) - embed.set_footer(text="Image by " + username + " on Unsplash.") - await ctx.send(embed=embed) + async with ctx.typing(): + async with aiohttp.ClientSession as session: + async with session.get( + 'https://api.unsplash.com/photos/random?query=earth&client_id=' + UnClientId + ) as r: + jsondata = await r.json() + await ctx.send("Still a placeholder") + def setup(bot: commands.Bot) -> None: |