Initial commit, refactored some things from original code and removed WP functionality

This commit is contained in:
Joan Cano
2023-03-06 17:04:59 +01:00
commit a4a76966fe
25 changed files with 517 additions and 0 deletions

32
bot/parser.py Normal file
View File

@@ -0,0 +1,32 @@
import helpers
def get_title(soup):
try:
title = soup.find("span", attrs={"id":'productTitle'})
title_value = title.string
title_string = title_value.strip()
except AttributeError as err:
helpers.logging.info(f"Couldn't get title: {err}")
title_string = ""
return title_string
def get_price(soup):
try:
price = soup.find("span", attrs={'class':'a-offscreen'}).string.strip()
# A veces mete el título en el precio
if "" not in price:
price = "N/A"
except AttributeError:
price = "N/A"
return price
def get_image(soup):
try:
image = soup.find("img", attrs={'id':'landingImage'})
image = image.get('src')
except AttributeError:
image = "N/A"
return image