Last active 1706137835

conk.py Raw
1#!/usr/bin/env python3
2from requests import Session, get, post
3from bs4 import BeautifulSoup as Soup
4
5# Config
6webhook = "" # discord webhook
7
8shop = {
9 # add entries for things you want to track
10 # copy the numeric IDs from urls
11 # e.g:
12 # https://www.coles.com.au/product/monster-ultra-rosa-multipack-cans-4-x-500ml-4-pack-3990033 => 3990033
13 # the fields are (coles, woolies, iga)
14 "coke": ("2993706", "623034", "848631"),
15 "monster": ("3990033", "143253", None),
16}
17# end Config
18
19class Price:
20 def __init__(self, coles, woolies, iga):
21 self.coles = coles
22 self.woolies = woolies
23 self.iga = iga
24
25 def sorted(self):
26 price = {}
27 if self.coles:
28 price["coles"] = self.coles
29 if self.woolies:
30 price["woolies"] = self.woolies
31 if self.iga:
32 price["iga"] = self.iga
33 return "\n".join(f"{name}: ${price:.2f}" for name,price in sorted(price.items(), key=lambda x: x[1]))
34
35out = {}
36
37for name,ids in shop.items():
38 coles,woolies,iga = None,None,None
39 if ids[0]:
40 coles = Soup(get(f"https://www.coles.com.au/product/{ids[0]}").text, "html.parser")
41 if ids[2]:
42 iga = get(f"https://www.igashop.com.au/api/storefront/stores/84996/products/{ids[2]}").json()
43
44 if ids[1]:
45 session = Session()
46 session.headers["User-Agent"] = 'Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/116.0'
47 session.get(f"https://www.woolworths.com.au/shop/productdetails/{ids[1]}")
48 woolies = session.get(f"https://www.woolworths.com.au/api/v3/ui/schemaorg/product/{ids[1]}").json()
49
50 out[name] = Price(
51 float(coles.findAll("span", class_="price__value")[0].text[1:]) if coles else 0.0,
52 woolies["offers"]["price"] if woolies else 0.0,
53 float(iga["price"][1:]) if iga else 0.0
54 )
55
56post(webhook, json={"content": "\n\n".join(f"**{name}**\n{price.sorted()}" for name,price in out.items())})