From 3dde1eabd4b8325a93ce734decfbe9c6ee3e1d76 Mon Sep 17 00:00:00 2001 From: Dustin Pianalto Date: Thu, 3 May 2018 12:04:54 -0800 Subject: [PATCH] Added ISS Location command --- exts/utils.py | 24 ++++++++++++++++++++++++ geeksbot.py | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/exts/utils.py b/exts/utils.py index b18de4a..f8baee4 100644 --- a/exts/utils.py +++ b/exts/utils.py @@ -11,6 +11,11 @@ from .imports import checks import pytz import gspread from oauth2client.service_account import ServiceAccountCredentials +import matplotlib as mpl +mpl.use('Agg') +import matplotlib.pyplot as plt +from mpl_toolkits.basemap import Basemap +from io import BytesIO config_dir = 'config/' admin_id_file = 'admin_ids' @@ -529,6 +534,25 @@ class Utils: value=f'Steam ID: {steam[i]}\nPatreon Level: {tier[i]}\nPatron of: {patron[i]}') await ctx.send(embed=em) + @commands.command(name='iss') + async def iss_loc(self, ctx): + async with self.bot.aio_session.get('https://api.wheretheiss.at/v1/satellites/25544') as response: + iss_loc = await response.json() + + lat = iss_loc['latitude'] + lon = iss_loc['longitude'] + plt.figure(figsize=(8, 8)) + m = Basemap(projection='ortho', resolution=None, lat_0=lat, lon_0=lon) + m.bluemarble(scale=0.5) + x, y = m(lon, lat) + plt.plot(x, y, 'ok', markersize=10, color='red') + plt.text(x, y, ' ISS', fontsize=20, color='red') + + with BytesIO() as output: + plt.savefig(output, format='png', transparent=True) + output.seek(0) + await ctx.send(file=discord.File(output, 'output.png')) + # TODO Create Help command diff --git a/geeksbot.py b/geeksbot.py index 7c84073..6264688 100644 --- a/geeksbot.py +++ b/geeksbot.py @@ -144,7 +144,7 @@ async def on_message(ctx): @bot.event async def on_ready(): - await bot.connect_db() + if bot.db_con is None: await bot.connect_db() bot.recent_msgs = {} for guild in bot.guilds: bot.recent_msgs[guild.id] = deque(maxlen=50)