Skip to content

Instantly share code, notes, and snippets.

@th0mas
Last active May 7, 2019 22:17
Show Gist options
  • Save th0mas/d0a263d2e0520d70380cc1a8273ea174 to your computer and use it in GitHub Desktop.
Save th0mas/d0a263d2e0520d70380cc1a8273ea174 to your computer and use it in GitHub Desktop.
Texts a number if Haagen Daas ice cream is cheap today
from bs4 import BeautifulSoup
from twilio.rest import Client
import requests
import re
CHEAP_PRICE = 2.50
TWILIO_ACCOUNT_SID = 'TWLILI_SID'
SECRET_KEY = 'TWILIO_SECRET'
TWILIO_NUMBER='00000000'
MY_NUMBER='00000000'
url = 'https://www.sainsburys.co.uk/shop/gb/groceries/häagen-dazs-vanilla-500ml'
r = requests.get(url.encode('utf-8').decode('latin-1'),
headers={'Content-type': 'text/plain; charset=utf-8'})
bs = BeautifulSoup(r.text, 'html.parser')
price = float(re.search('(\d)+.(\d){2}', bs.find_all('p', 'pricePerUnit')[0].get_text().strip().split('/')[0])[0])
# Twilio
client = Client(TWILIO_ACCOUNT_SID, SECRET_KEY)
if price <= CHEAP_PRICE:
message = 'Haagen Daas is cheap go to sainsburys'
else:
message = 'Haagen Daas is not cheap today'
txt = client.messages \
.create(
body=message,
from_=TWILIO_NUMBER,
to=MY_NUMBER
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment