Files
web-scraper/scrape.py
2021-03-05 16:16:51 +00:00

46 lines
1.5 KiB
Python

import requests
from twilio.rest import Client
import os
from sys import exit
from pathlib import Path
from dotenv import load_dotenv
load_dotenv(verbose=True)
api_url = 'https://www.boden.co.uk/api/stock/v1/styles?market=UK&language=en-gb&id=y1357'
website_url = 'https://www.boden.co.uk/en-gb/rainbow-3-in-1-printed-jacket/sty-y1357'
# 40263447 low stock
# 40263442 12-18m
item_id = '40263442'
message_sent_file = './sent.txt'
if os.path.isfile(message_sent_file):
print("We have already sent SMS")
exit()
r = requests.get(api_url)
j = r.json()
for id in j['Y1357']:
if id['edp'] == item_id:
if id['stockStatus'] == 'OutOfStock':
print(f"Item is out of stock")
else:
print(f"Item is in stock")
Path(message_sent_file).touch()
# Your Account Sid and Auth Token from twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
client = Client(account_sid, auth_token)
message = client.messages.create(
messaging_service_sid='MG18978bd18247c16cc39d743251106813',
body='The coat is in stock at ' + website_url,
to='+447557447469'
)
print(message.sid)