Getting rid of the try except and re-wording some things

This commit is contained in:
Luke Robles 2023-06-16 15:16:22 -07:00
parent 0ca8f3d50b
commit 60f5cc04f8

View File

@ -220,31 +220,31 @@ async def calculate_trade_profies(commodity, scu=None):
)
response = requests.get(url, headers=headers).json()["data"]
if not response:
embed.set_author(name="❌ Couldnt find that commodity: %s" % commodity)
embed.set_author(name="❌ Couldnt find that commodity: %s\n\nDid you make a typo?" % commodity)
return embed
embed.set_author(name=commodity)
embed.set_thumbnail(
url="https://media.starcitizen.tools/thumb/b/bb/Shubin_logo_circle.png/120px-Shubin_logo_circle.png"
)
# Loop through every system/outpost and find the cheapest place selling the commodity
try:
costs = {}
for systems, stations in response.items():
for station, trades in stations.items():
if "buy" in trades and commodity in trades["buy"]:
costs[station] = trades["buy"][commodity] * int(scu)
break
costs = {}
for systems, stations in response.items():
for station, trades in stations.items():
if "buy" in trades and commodity in trades["buy"]:
costs[station] = trades["buy"][commodity] * int(scu)
break
embed.add_field(
name="**Cheapest place to fill %s of %s**" % (scu_string, commodity),
value="%s: $%s"
% (
min(costs, key=costs.get),
"{:20,.2f}".format(costs[min(costs, key=costs.get)]).strip(),
),
inline=True,
)
except Exception:
pass
embed.add_field(
name="**Best place to buy %s of %s**" % (scu_string, commodity),
value="%s: $%s"
% (
min(costs, key=costs.get),
"{:20,.2f}".format(costs[min(costs, key=costs.get)]).strip(),
),
inline=True,
)
# Same logic, but finding the place buying the commodity for the most
profits = {}
@ -255,7 +255,7 @@ async def calculate_trade_profies(commodity, scu=None):
break
embed.add_field(
name="Most profitable place to sell %s of %s" % (scu_string, commodity),
name="Best palce to sell %s of %s" % (scu_string, commodity),
value="%s: $%s"
% (
max(profits, key=profits.get),