def find_price(my_wish): print('++Finding latest price from wish list') lists = {} for products in my_wish: temp = amazon_product.amazon_product splitted = str(products.encode('ascii', 'ignore')).split("/") asin = splitted[2] html_doc = (search_product(products, False)) soup = BeautifulSoup(html_doc, 'html.parser') print(soup.title.contents[0]) title = (soup.title.contents[0]).replace("'", "") temp.title = str(title) deal = soup.find(id="priceblock_dealprice") sale = soup.find(id="priceblock_saleprice") our = soup.find(id="priceblock_ourprice") lable = "" if deal is not None: print("Deal price:" + deal.contents[1]) current_price = float(str(deal.contents[1]).replace(',', '')) lable = "Deal" else: if sale is not None: print("Sale price:" + sale.contents[1]) current_price = float(str(sale.contents[1]).replace(',', '')) lable = "Sale" else: if our is not None: print("Amazon price:" + our.contents[1]) current_price = float( str(our.contents[1]).replace(',', '')) lable = "Amazon" else: print("Out of stock!") current_price = 0 lable = "Out Of Stock" temp = amazon_product.amazon_product(asin=asin, title=title, current_price=current_price, lable=lable) lists.update({temp.asin: temp}) return lists
def fetch_products(): connection = connect() cursor = connection.cursor() query = 'select ASIN,CURRENT_PRICE,TITLE,PRICE_LABLE from amazon' stored_date = {} try: cursor.execute(query) result = cursor.fetchall() for rows in result: asin = rows[0].encode('utf8') current_price = rows[1] title = rows[2].encode('utf8') lable = rows[3].encode('utf8') temp = amazon_product.amazon_product(asin=asin, title=title, current_price=current_price, lable=lable) # print(temp) stored_date.update({temp.asin: temp}) return stored_date except mysql.connector.errors: print(mysql.connector.errors) finally: connection.close()
def find_price(my_wish): print('++Finding latest price from wish list') lists = {} for products in my_wish: temp = amazon_product.amazon_product splitted = str(products.encode('ascii', 'ignore')).split("/") asin = splitted[2] html_doc = (search_product(products, False)) soup = BeautifulSoup(html_doc, 'html.parser') print(soup.title.contents[0]) title = (soup.title.contents[0]).replace("'", "") temp.title = str(title) deal = soup.find(id="priceblock_dealprice") sale = soup.find(id="priceblock_saleprice") our = soup.find(id="priceblock_ourprice") lable="" if deal is not None: print("Deal price:"+deal.contents[1]) current_price = float(str(deal.contents[1]).replace(',', '')) lable = "Deal" else: if sale is not None: print("Sale price:"+sale.contents[1]) current_price = float(str(sale.contents[1]).replace(',', '')) lable = "Sale" else: if our is not None: print("Amazon price:"+our.contents[1]) current_price = float(str(our.contents[1]).replace(',', '')) lable = "Amazon" else: print("Out of stock!") current_price = 0 lable = "Out Of Stock" temp = amazon_product.amazon_product(asin=asin, title=title, current_price=current_price, lable=lable) lists.update({temp.asin: temp}) return lists