Fix pricing information for ships

This commit is contained in:
Luke Robles 2023-12-22 13:34:30 -08:00
parent f52da8943f
commit d8a9886b6d

View File

@ -52,11 +52,21 @@ def write_incident_file(file_path, url, details):
async def rsi_find(player):
url = "https://api.starcitizen-api.com/%s/v1/live/user/%s" % (
player_url = "https://api.starcitizen-api.com/%s/v1/live/user/%s" % (
os.getenv("star_citizen_token").replace('"', ""),
player,
)
response = requests.get(url).json()
response = requests.get(player_url).json()
if not response["data"]:
embed = discord.Embed(
description="❌❌❌",
color=discord.Color.red(),
type="rich",
title="Player does not exist",
)
return embed
embed = discord.Embed(
description="-------",
color=discord.Color.blue(),
@ -69,10 +79,15 @@ async def rsi_find(player):
value=response["data"]["profile"]["page"]["url"],
inline=False,
)
embed.add_field(
name="Player ID",
value=response["data"]["profile"]["id"],
inline=True,
)
embed.add_field(
name="Enlisted",
value=response["data"]["profile"]["enlisted"].split("T")[0],
inline=False,
inline=True,
)
embed.set_author(
@ -84,12 +99,31 @@ async def rsi_find(player):
embed.add_field(name="-------", value="", inline=False)
if "name" in response["data"]["organization"]:
org_url = "https://api.starcitizen-api.com/%s/v1/live/organization/%s" % (
os.getenv("star_citizen_token").replace('"', ""),
response["data"]["organization"]["sid"],
)
org_response = requests.get(org_url).json()
embed.add_field(
name="Org Info",
value=response["data"]["organization"]["name"],
value="[%s](%s)"
% (org_response["data"]["sid"], org_response["data"]["url"]),
inline=True,
)
embed.add_field(
name="Rank",
value=response["data"]["organization"]["rank"],
inline=True,
)
embed.add_field(
name="Number of members",
value=org_response["data"]["members"],
inline=False,
)
embed.set_image(url=response["data"]["organization"]["image"])
embed.set_image(url=org_response["data"]["logo"])
else:
embed.add_field(name="Org Info", value="Player is not in an org", inline=False)
@ -152,9 +186,28 @@ async def get_ship(ship_name):
ship_role = ""
embed.add_field(name="**Role**", value=ship_role)
try:
item_uuid = (
soup.find("div", {"class": "infobox__label"}, string="UUID")
.findNext("div", {"class": "infobox__data"})
.text
)
except Exception:
item_uuid = "N/A"
embed.set_footer(text="item UUID: %s" % item_uuid)
try:
ingame_price = soup.find("td", {"class": "Price smwtype_qty"}).text
ingame_price = requests.get(
"https://finder.cstone.space/ShipShops1/%s" % item_uuid
).text
price_soup = BeautifulSoup(ingame_price, "html.parser")
table = price_soup.find("div", class_="pricetab").find_next("table")
second_row = table.find_all("tr")[1]
ingame_price = (
second_row.find_all("td")[1].get_text(strip=True).replace(" ", ",")
)
price = "[%s](%s%s#Universe_availability)" % (
ingame_price,
@ -359,16 +412,6 @@ async def get_ship(ship_name):
name="**Link**", value="%s%s" % (wiki_url, wiki_ship_name), inline=False
)
try:
item_uuid = (
soup.find("div", {"class": "infobox__label"}, string="UUID")
.findNext("div", {"class": "infobox__data"})
.text
)
except Exception:
item_uuid = "N/A"
embed.set_footer(text="item UUID: %s" % item_uuid)
except Exception as e:
print(e)
embed = discord.Embed(description="", color=discord.Color.red(), type="rich")