Fix edge case of a commodity not actually being sold anywhere, but it still being able to be bought (Bexalite)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
3fac36ab57
commit
19d9c94ae3
@ -3,6 +3,11 @@ import requests
|
|||||||
import discord
|
import discord
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
# prints for debug
|
||||||
|
import pprint
|
||||||
|
|
||||||
|
pp = pprint.PrettyPrinter(indent=4)
|
||||||
|
|
||||||
wiki_url = "https://starcitizen.tools/"
|
wiki_url = "https://starcitizen.tools/"
|
||||||
|
|
||||||
|
|
||||||
@ -206,7 +211,7 @@ async def calculate_trade_profies(commodity, scu=None):
|
|||||||
scu_string = "%s scu" % scu
|
scu_string = "%s scu" % scu
|
||||||
if not scu:
|
if not scu:
|
||||||
scu = 696
|
scu = 696
|
||||||
scu_string = "a C2 Hercules"
|
scu_string = "a C2 Hercules full"
|
||||||
|
|
||||||
commodity = commodity.capitalize()
|
commodity = commodity.capitalize()
|
||||||
|
|
||||||
@ -215,13 +220,20 @@ async def calculate_trade_profies(commodity, scu=None):
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
response = requests.get(url, headers=headers).json()["data"]
|
response = requests.get(url, headers=headers).json()["data"]
|
||||||
|
except Exception:
|
||||||
|
print(commodity)
|
||||||
embed.set_author(
|
embed.set_author(
|
||||||
name=commodity,
|
name="❌ Couldnt find that commodity",
|
||||||
url="%s%s" % (wiki_url, commodity),
|
url="%s%s" % (wiki_url, commodity),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Loop through every system/outpost and find the cheapest place selling the commodity
|
embed.set_author(
|
||||||
|
name=commodity,
|
||||||
|
url="%s%s" % (wiki_url, 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():
|
||||||
@ -230,7 +242,7 @@ async def calculate_trade_profies(commodity, scu=None):
|
|||||||
break
|
break
|
||||||
|
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="**Cheapest place to fill %s**" % scu_string,
|
name="**Cheapest place to fill %s of %s**" % (scu_string, commodity),
|
||||||
value="%s: $%s"
|
value="%s: $%s"
|
||||||
% (
|
% (
|
||||||
min(costs, key=costs.get),
|
min(costs, key=costs.get),
|
||||||
@ -238,40 +250,35 @@ async def calculate_trade_profies(commodity, scu=None):
|
|||||||
),
|
),
|
||||||
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 = {}
|
||||||
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 "sell" in trades and commodity in trades["sell"]:
|
if "sell" in trades and commodity in trades["sell"]:
|
||||||
profits[station] = trades["sell"][commodity] * int(scu)
|
profits[station] = trades["sell"][commodity] * int(scu)
|
||||||
break
|
break
|
||||||
|
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="Most profitable place to sell %s" % scu_string,
|
name="Most profitable place to sell %s of " % (scu_string, commodity),
|
||||||
value="%s: $%s"
|
value="%s: $%s"
|
||||||
% (
|
% (
|
||||||
max(profits, key=profits.get),
|
max(profits, key=profits.get),
|
||||||
"{:20,.2f}".format(profits[max(profits, key=profits.get)]).strip(),
|
"{:20,.2f}".format(profits[max(profits, key=profits.get)]).strip(),
|
||||||
),
|
),
|
||||||
inline=True,
|
inline=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if len(costs) and len(profits):
|
||||||
net_profit = float(profits[max(profits, key=profits.get)]) - float(
|
net_profit = float(profits[max(profits, key=profits.get)]) - float(
|
||||||
costs[min(costs, key=costs.get)]
|
costs[min(costs, key=costs.get)]
|
||||||
)
|
)
|
||||||
|
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="**Net Profit**",
|
name="**Net Profit**",
|
||||||
value="$%s" % "{:20,.2f}".format(net_profit).strip(),
|
value="$%s" % "{:20,.2f}".format(net_profit).strip(),
|
||||||
inline=True,
|
inline=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
return embed
|
return embed
|
||||||
except Exception:
|
|
||||||
print(commodity)
|
|
||||||
embed.set_author(
|
|
||||||
name="❌ Couldnt find that commodity",
|
|
||||||
url="%s%s" % (wiki_url, commodity),
|
|
||||||
)
|
|
||||||
return embed
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user