From 217faa3d0c6e16ef414b06c7fd596e527456b7bb Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sat, 29 Apr 2023 08:29:15 -0700 Subject: [PATCH] Adding some horrendous code to figureo ut where to buy each ship --- app/star_citizen.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/star_citizen.py b/app/star_citizen.py index f4eb3178..7cc32d29 100644 --- a/app/star_citizen.py +++ b/app/star_citizen.py @@ -29,11 +29,28 @@ async def get_ship(ship_name): 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 + # 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)