Fixing the code that gets all ships for /ship
This commit is contained in:
parent
72346ff2c4
commit
564e79b3f9
@ -65,32 +65,15 @@ class StarCitizen(commands.Cog):
|
|||||||
"""
|
"""
|
||||||
returns a list of all ships in the game, which can then be passed to the /ship command for auto complete
|
returns a list of all ships in the game, which can then be passed to the /ship command for auto complete
|
||||||
"""
|
"""
|
||||||
url = "https://starcitizen.tools/List_of_pledge_vehicles"
|
url = "https://starcitizen.tools/Category:Ships"
|
||||||
|
|
||||||
response = requests.get(url).text
|
response = requests.get(url).text
|
||||||
soup = BeautifulSoup(response, "html.parser")
|
soup = BeautifulSoup(response, "html.parser")
|
||||||
|
|
||||||
# Find the table with the "Name" row
|
all_ships = [
|
||||||
table = soup.find("table", {"class": "wikitable"})
|
a.text for a in soup.select("div.mw-category.mw-category-columns a")
|
||||||
name_column_index = None
|
]
|
||||||
|
|
||||||
# Find the index of the "Name" column
|
|
||||||
header_row = table.find("tr")
|
|
||||||
headers = header_row.find_all("th")
|
|
||||||
for i, header in enumerate(headers):
|
|
||||||
if header.text.strip() == "Name":
|
|
||||||
name_column_index = i
|
|
||||||
break
|
|
||||||
|
|
||||||
if name_column_index is not None:
|
|
||||||
# Extract all the items in the "Name" column
|
|
||||||
all_ships = []
|
|
||||||
rows = table.find_all("tr")
|
|
||||||
for row in rows[1:]: # Skip the header row
|
|
||||||
columns = row.find_all("td")
|
|
||||||
if len(columns) > name_column_index:
|
|
||||||
name = columns[name_column_index].text.strip()
|
|
||||||
all_ships.append(name)
|
|
||||||
return all_ships
|
return all_ships
|
||||||
|
|
||||||
@commands.slash_command(
|
@commands.slash_command(
|
||||||
@ -269,7 +252,7 @@ class StarCitizen(commands.Cog):
|
|||||||
url="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png"
|
url="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png"
|
||||||
)
|
)
|
||||||
embed.set_author(
|
embed.set_author(
|
||||||
name="⚠️ THERE HAS BEEN AN UPDATE TO THE ONGOING INCIDENT ⚠️\n"
|
name="⚠️ THERE HAS BEEN AN UPDATE TO THE ONGOING INCIDENT ⚠️"
|
||||||
)
|
)
|
||||||
# embed.set_image(
|
# embed.set_image(
|
||||||
# url="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif"
|
# url="https://media.giphy.com/media/WWIZJyXHXscn8JC1e0/giphy.gif"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user