Update launchlib to version 2
This commit is contained in:
parent
8b1ac18609
commit
221ca4074b
@ -8,7 +8,7 @@
|
|||||||
"install_msg": "Thank you for installing LaunchLib. Get started with `[p]load launchlib`, then `[p]help LaunchLib`",
|
"install_msg": "Thank you for installing LaunchLib. Get started with `[p]load launchlib`, then `[p]help LaunchLib`",
|
||||||
"short": "Access launch data for space flights",
|
"short": "Access launch data for space flights",
|
||||||
"end_user_data_statement": "This cog does not store any End User Data",
|
"end_user_data_statement": "This cog does not store any End User Data",
|
||||||
"requirements": ["python-launch-library>=1.0.6"],
|
"requirements": ["python-launch-library>=2.0.3"],
|
||||||
"tags": [
|
"tags": [
|
||||||
"bobloy",
|
"bobloy",
|
||||||
"utils",
|
"utils",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
import discord
|
import discord
|
||||||
import launchlibrary as ll
|
import launchlibrary as ll
|
||||||
from redbot.core import Config, commands
|
from redbot.core import Config, commands
|
||||||
@ -14,9 +14,7 @@ log = logging.getLogger("red.fox_v3.launchlib")
|
|||||||
|
|
||||||
class LaunchLib(commands.Cog):
|
class LaunchLib(commands.Cog):
|
||||||
"""
|
"""
|
||||||
Cog Description
|
Cog using `thespacedevs` API to get details about rocket launches
|
||||||
|
|
||||||
Less important information about the cog
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, bot: Red):
|
def __init__(self, bot: Red):
|
||||||
@ -37,27 +35,86 @@ class LaunchLib(commands.Cog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
async def _embed_launch_data(self, launch: ll.AsyncLaunch):
|
async def _embed_launch_data(self, launch: ll.AsyncLaunch):
|
||||||
status: ll.AsyncLaunchStatus = await launch.get_status()
|
|
||||||
|
if False:
|
||||||
|
example_launch = ll.AsyncLaunch(
|
||||||
|
id="9279744e-46b2-4eca-adea-f1379672ec81",
|
||||||
|
name="Atlas LV-3A | Samos 2",
|
||||||
|
tbddate=False,
|
||||||
|
tbdtime=False,
|
||||||
|
status={"id": 3, "name": "Success"},
|
||||||
|
inhold=False,
|
||||||
|
windowstart="1961-01-31 20:21:19+00:00",
|
||||||
|
windowend="1961-01-31 20:21:19+00:00",
|
||||||
|
net="1961-01-31 20:21:19+00:00",
|
||||||
|
info_urls=[],
|
||||||
|
vid_urls=[],
|
||||||
|
holdreason=None,
|
||||||
|
failreason=None,
|
||||||
|
probability=0,
|
||||||
|
hashtag=None,
|
||||||
|
agency=None,
|
||||||
|
changed=None,
|
||||||
|
pad=ll.Pad(
|
||||||
|
id=93,
|
||||||
|
name="Space Launch Complex 3W",
|
||||||
|
latitude=34.644,
|
||||||
|
longitude=-120.593,
|
||||||
|
map_url="http://maps.google.com/maps?q=34.644+N,+120.593+W",
|
||||||
|
retired=None,
|
||||||
|
total_launch_count=3,
|
||||||
|
agency_id=161,
|
||||||
|
wiki_url=None,
|
||||||
|
info_url=None,
|
||||||
|
location=ll.Location(
|
||||||
|
id=11,
|
||||||
|
name="Vandenberg AFB, CA, USA",
|
||||||
|
country_code="USA",
|
||||||
|
total_launch_count=83,
|
||||||
|
total_landing_count=3,
|
||||||
|
pads=None,
|
||||||
|
),
|
||||||
|
map_image="https://spacelaunchnow-prod-east.nyc3.digitaloceanspaces.com/media/launch_images/pad_93_20200803143225.jpg",
|
||||||
|
),
|
||||||
|
rocket=ll.Rocket(
|
||||||
|
id=2362,
|
||||||
|
name=None,
|
||||||
|
default_pads=None,
|
||||||
|
family=None,
|
||||||
|
wiki_url=None,
|
||||||
|
info_url=None,
|
||||||
|
image_url=None,
|
||||||
|
),
|
||||||
|
missions=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
# status: ll.AsyncLaunchStatus = await launch.get_status()
|
||||||
|
status = launch.status
|
||||||
|
|
||||||
rocket: ll.AsyncRocket = launch.rocket
|
rocket: ll.AsyncRocket = launch.rocket
|
||||||
|
|
||||||
title = launch.name
|
title = launch.name
|
||||||
description = status.description
|
description = status["name"]
|
||||||
|
|
||||||
urls = launch.vid_urls + launch.info_urls
|
urls = launch.vid_urls + launch.info_urls
|
||||||
if not urls and rocket:
|
if rocket:
|
||||||
urls = rocket.info_urls + [rocket.wiki_url]
|
urls += [rocket.info_url, rocket.wiki_url]
|
||||||
|
if launch.pad:
|
||||||
|
urls += [launch.pad.info_url, launch.pad.wiki_url]
|
||||||
|
|
||||||
if urls:
|
if urls:
|
||||||
url = urls[0]
|
url = next((url for url in urls if urls is not None), None)
|
||||||
else:
|
else:
|
||||||
url = None
|
url = None
|
||||||
|
|
||||||
color = discord.Color.green() if status.id in [1, 3] else discord.Color.red()
|
color = discord.Color.green() if status["id"] in [1, 3] else discord.Color.red()
|
||||||
|
|
||||||
em = discord.Embed(title=title, description=description, url=url, color=color)
|
em = discord.Embed(title=title, description=description, url=url, color=color)
|
||||||
|
|
||||||
if rocket and rocket.image_url and rocket.image_url != "Array":
|
if rocket and rocket.image_url and rocket.image_url != "Array":
|
||||||
em.set_image(url=rocket.image_url)
|
em.set_image(url=rocket.image_url)
|
||||||
|
elif launch.pad and launch.pad.map_image:
|
||||||
|
em.set_image(url=launch.pad.map_image)
|
||||||
|
|
||||||
agency = getattr(launch, "agency", None)
|
agency = getattr(launch, "agency", None)
|
||||||
if agency is not None:
|
if agency is not None:
|
||||||
@ -89,6 +146,16 @@ class LaunchLib(commands.Cog):
|
|||||||
data = mission.get(f[0], None)
|
data = mission.get(f[0], None)
|
||||||
if data is not None and data:
|
if data is not None and data:
|
||||||
em.add_field(name=f[1], value=data)
|
em.add_field(name=f[1], value=data)
|
||||||
|
if launch.pad:
|
||||||
|
location_url = getattr(launch.pad, "map_url", None)
|
||||||
|
pad_name = getattr(launch.pad, "name", None)
|
||||||
|
|
||||||
|
if pad_name is not None:
|
||||||
|
if location_url is not None:
|
||||||
|
location_url = re.sub("[^a-zA-Z0-9/:.'+\"°?=,-]", "", location_url) # Fix bad URLS
|
||||||
|
em.add_field(name="Launch Pad Name", value=f"[{pad_name}]({location_url})")
|
||||||
|
else:
|
||||||
|
em.add_field(name="Launch Pad Name", value=pad_name)
|
||||||
|
|
||||||
if rocket and rocket.family:
|
if rocket and rocket.family:
|
||||||
em.add_field(name="Rocket Family", value=rocket.family)
|
em.add_field(name="Rocket Family", value=rocket.family)
|
||||||
@ -101,11 +168,17 @@ class LaunchLib(commands.Cog):
|
|||||||
|
|
||||||
@commands.group()
|
@commands.group()
|
||||||
async def launchlib(self, ctx: commands.Context):
|
async def launchlib(self, ctx: commands.Context):
|
||||||
|
"""Base command for getting launches"""
|
||||||
if ctx.invoked_subcommand is None:
|
if ctx.invoked_subcommand is None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@launchlib.command()
|
@launchlib.command()
|
||||||
async def next(self, ctx: commands.Context, num_launches: int = 1):
|
async def next(self, ctx: commands.Context, num_launches: int = 1):
|
||||||
|
"""
|
||||||
|
Show the next launches
|
||||||
|
|
||||||
|
Use `num_launches` to get more than one.
|
||||||
|
"""
|
||||||
# launches = await api.async_next_launches(num_launches)
|
# launches = await api.async_next_launches(num_launches)
|
||||||
# loop = asyncio.get_running_loop()
|
# loop = asyncio.get_running_loop()
|
||||||
#
|
#
|
||||||
@ -115,6 +188,8 @@ class LaunchLib(commands.Cog):
|
|||||||
#
|
#
|
||||||
launches = await self.api.async_fetch_launch(num=num_launches)
|
launches = await self.api.async_fetch_launch(num=num_launches)
|
||||||
|
|
||||||
|
# log.debug(str(launches))
|
||||||
|
|
||||||
async with ctx.typing():
|
async with ctx.typing():
|
||||||
for x, launch in enumerate(launches):
|
for x, launch in enumerate(launches):
|
||||||
if x >= num_launches:
|
if x >= num_launches:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user