12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- from bs4 import BeautifulSoup
- import requests
- import time
- from bot_buy import Messenger
- ### lists.txt format
- ### url,expected price,product name
- url = ""
- m = Messenger()
- while (1):
- with open('list.txt', 'r') as f:
- lines = f.readlines()
- for l in lines:
- url = l.split(',')[0].rstrip()
- price = float(l.split(',')[1].rstrip())
- prod = l.split(',')[2].rstrip()
-
- try:
- r = requests.get(url)
- except:
- print('failed to request')
- continue
-
- soup = BeautifulSoup(r.text, 'html.parser')
- #print(soup.prettify())
- price_normal = soup.find('span', class_="preco_desconto")
- price_bf = soup.find('span', class_="preco_desconto_avista-cm")
- if price_normal:
- price_normal = price_normal.find('strong')
- spans = [price_normal, price_bf]
- #print(type(price_bf))
-
- for s in spans:
- if s:
- try:
- new_price = float(s.get_text().split(' ')[1].replace(".","").replace(',', '.'))
- print(f"Produto: {prod} -> Esperado: {price} -> Agora: {new_price}")
- if new_price <= price:
- m.sendMessage(f"Got it! {prod} -> {new_price}\n{url}")
- except:
- print(f"failed to parse {new_price}")
- time.sleep(10)
- time.sleep(120)
|