144 lines
4.9 KiB
Python
144 lines
4.9 KiB
Python
from bs4 import BeautifulSoup
|
|
import requests
|
|
import discord
|
|
|
|
|
|
async def get_ship(ship_name):
|
|
base_url = "https://robertspaceindustries.com"
|
|
wiki_url = "https://starcitizen.tools/"
|
|
|
|
try:
|
|
wiki_ship_name = "_".join(elem.capitalize() for elem in ship_name.split())
|
|
|
|
# print(wiki_ship_name)
|
|
# print("%s%s" % (wiki_url, wiki_ship_name))
|
|
|
|
headers = {
|
|
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/112.0"
|
|
}
|
|
response = requests.get(wiki_url + wiki_ship_name, headers=headers).text
|
|
soup = BeautifulSoup(response, "html.parser")
|
|
|
|
embed = discord.Embed(
|
|
description="-------", color=discord.Color.blue(), type="rich"
|
|
)
|
|
|
|
ship_image = (soup.find("a", {"class": "mw-file-description"})).img["src"]
|
|
|
|
embed.set_thumbnail(url=ship_image)
|
|
|
|
embed.set_author(name="Info about the %s" % ship_name)
|
|
try:
|
|
# ingame_price = (
|
|
# soup.find("div", {"class": "data-buycost infobox-data infobox-col2"})
|
|
# .find("div", {"class": "infobox-data__value"})
|
|
# .text
|
|
# )
|
|
|
|
# Hideous code for "where to buy" in game
|
|
table = soup.find("span", {"id": "Buying"}).findNext(
|
|
"table", {"class": "wikitable"}
|
|
)
|
|
|
|
locations = [x.text.replace("\n", "") for x in table.find_all("th")]
|
|
prices = [x.text.replace("\n", "") for x in table.find_all("td")]
|
|
zip_list = zip(locations, prices)
|
|
|
|
result = list(zip_list)
|
|
ingame_price = [x for x in result if "Unavailable" not in x]
|
|
for x in ingame_price:
|
|
ingame_price = " ".join(x) + " aUEC"
|
|
|
|
# embed.add_field(name="**Where to buy**", value=result, inline=True)
|
|
|
|
except Exception:
|
|
ingame_price = "No in-game price available"
|
|
embed.add_field(name="**Ingame Price**", value=ingame_price, inline=True)
|
|
|
|
pledge_price = (
|
|
soup.find("div", {"class": "data-pledgecost infobox-data infobox-col4"})
|
|
.find("div", {"class": "infobox-data__value"})
|
|
.text
|
|
)
|
|
|
|
embed.add_field(name="**Pledge Price**", value=pledge_price, inline=True)
|
|
|
|
# embed.add_field(name="-------", value="", inline=False)
|
|
# embed.add_field(name="**Description**", value=ship["description"], inline=False)
|
|
embed.add_field(name="-------", value="", inline=False)
|
|
|
|
stowage_capacity = (
|
|
soup.find("tr", {"class": "data-stowagespace infobox-data infobox-col2"})
|
|
.findChildren("td")[0]
|
|
.text
|
|
)
|
|
|
|
embed.add_field(
|
|
name="**Stowage Capacity**", value=stowage_capacity, inline=True
|
|
)
|
|
|
|
cargo_capacity = (
|
|
soup.find("tr", {"class": "data-cargocapacity infobox-data infobox-col4"})
|
|
.findChildren("td")[0]
|
|
.text
|
|
)
|
|
|
|
embed.add_field(name="**Cargo Capacity**", value=cargo_capacity, inline=True)
|
|
|
|
crew_size = (
|
|
soup.find("tr", {"class": "data-crew infobox-data infobox-col4"})
|
|
.findChildren("td")[0]
|
|
.text
|
|
)
|
|
embed.add_field(name="**Crew Size**", value=crew_size, inline=True)
|
|
embed.add_field(name="-------", value="", inline=False)
|
|
|
|
claim_time = (
|
|
soup.find("div", {"class": "data-claimtime infobox-data infobox-col4"})
|
|
.find("div", {"class": "infobox-data__value"})
|
|
.text
|
|
)
|
|
embed.add_field(name="**Insurance claim time**", value=claim_time, inline=True)
|
|
|
|
try:
|
|
expedited_claim_time = (
|
|
soup.find(
|
|
"div", {"class": "data-expeditetime infobox-data infobox-col4"}
|
|
)
|
|
.find("div", {"class": "infobox-data__value"})
|
|
.text
|
|
)
|
|
embed.add_field(
|
|
name="**Expedite claim time**", value=expedited_claim_time, inline=True
|
|
)
|
|
except Exception:
|
|
pass
|
|
|
|
try:
|
|
expedited_fee = (
|
|
soup.find(
|
|
"div", {"class": "data-expeditecost infobox-data infobox-col2"}
|
|
)
|
|
.find("div", {"class": "infobox-data__value"})
|
|
.text
|
|
)
|
|
embed.add_field(name="**Expedite Fee**", value=expedited_fee, inline=True)
|
|
except Exception:
|
|
pass
|
|
|
|
embed.add_field(
|
|
name="**Link**", value="%s%s" % (wiki_url, wiki_ship_name), inline=False
|
|
)
|
|
|
|
except Exception as e:
|
|
embed = discord.Embed(description="❌", color=discord.Color.red(), type="rich")
|
|
embed.add_field(
|
|
name="**Could not find that ship**",
|
|
value="You gave me %s. Did you spell it right? (Its also possible my shitty code isnt working right)"
|
|
% ship_name,
|
|
inline=True,
|
|
)
|
|
return embed
|
|
|
|
return embed
|