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 efdf6313b0
commit a1323e2ad3

View File

@ -220,31 +220,31 @@ async def calculate_trade_profies(commodity, scu=None):
) )
response = requests.get(url, headers=headers).json()["data"] response = requests.get(url, headers=headers).json()["data"]
if not response: 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 return embed
embed.set_author(name=commodity) 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 # Loop through every system/outpost and find the cheapest place selling the commodity
try: costs = {}
costs = {} for systems, stations in response.items():
for systems, stations in response.items(): for station, trades in stations.items():
for station, trades in stations.items(): if "buy" in trades and commodity in trades["buy"]:
if "buy" in trades and commodity in trades["buy"]: costs[station] = trades["buy"][commodity] * int(scu)
costs[station] = trades["buy"][commodity] * int(scu) break
break
embed.add_field( embed.add_field(
name="**Cheapest place to fill %s of %s**" % (scu_string, commodity), name="**Best place to buy %s of %s**" % (scu_string, commodity),
value="%s: $%s" value="%s: $%s"
% ( % (
min(costs, key=costs.get), min(costs, key=costs.get),
"{:20,.2f}".format(costs[min(costs, key=costs.get)]).strip(), "{:20,.2f}".format(costs[min(costs, key=costs.get)]).strip(),
), ),
inline=True, inline=True,
) )
except Exception:
pass
# Same logic, but finding the place buying the commodity for the most # Same logic, but finding the place buying the commodity for the most
profits = {} profits = {}
@ -255,7 +255,7 @@ async def calculate_trade_profies(commodity, scu=None):
break break
embed.add_field( 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" value="%s: $%s"
% ( % (
max(profits, key=profits.get), max(profits, key=profits.get),