diff --git a/listing.py b/listing.py index e3df0c2..a9d553b 100644 --- a/listing.py +++ b/listing.py @@ -1,21 +1,27 @@ import requests import re, json - from datetime import datetime, timezone, timedelta +import functions + JST = timezone(timedelta(hours = 9)) class YahooAuctionsItem: - def __init__(self, name, url): - self.name = name - self.url = url - self.last_checked = datetime.fromisoformat('1970-01-01') - self.available = True - self.update() + def __init__(self, name: str, url: str): + # note - incoming url is not validated in any way! + self.name = name + self.url = re.match(url.rstrip("/"), r"([^?]+)") # remove trailing slashes and query params + self.id = re.match(self.url, r".+\/(.+?)$") # extract "x12345" from "https://buyee.jp/whatever/blah/x12345" + self.last_checked = datetime.fromisoformat('1970-01-01') + self.available = True + self.update() def update(self): try: + # the good news is, yahoo japan returns all the data we need in handy json format + # the bad news is that the only way to get that json format is to download the whole auction page and grep it + # r = requests.get("https://page.auctions.yahoo.co.jp/jp/auction/k487846283").text r = open("yahoo.html").read() j = json.loads(re.match(r'.*var pageData ?= ?(\{.*?\});', r, re.DOTALL).group(1))