updated part alerts parsing

This commit is contained in:
Giulio De Pasquale 2021-06-21 15:16:13 +01:00
parent 28ce89abef
commit a0243fab2f

15
app.py
View File

@ -33,7 +33,7 @@ if not token:
exit(0) exit(0)
bot = discum.Client(token=token, log={"console": False, "file": False}) bot = discum.Client(token=token, log=False)
######################################## ########################################
# Callbacks # Callbacks
@ -42,7 +42,7 @@ bot = discum.Client(token=token, log={"console": False, "file": False})
def get_soup(url: str): def get_soup(url: str):
r = requests.get(url) r = requests.get(url)
return BeautifulSoup(r.text) return BeautifulSoup(r.text, features="lxml")
def get_stockinformer_url(url: str) -> str: def get_stockinformer_url(url: str) -> str:
@ -60,15 +60,10 @@ def get_partalert_url(url: str) -> str:
for a in bs.find_all("a"): for a in bs.find_all("a"):
if "amazon" in a.text.lower(): if "amazon" in a.text.lower():
amazon_url = a.get("href") # remove tags and referrals
amazon_url = a.get("href").split("?")[0]
try: ret_url = amazon_url
asin = PARTALERT_ASIN.search(amazon_url).group('asin')
tld = PARTALERT_TLD.search(amazon_url).group('tld')
ret_url = f"https://amazon{tld}/dp/{asin}"
except Exception as e:
print(f"Exception: {e}")
return ret_url return ret_url