36 lines
955 B
Python
36 lines
955 B
Python
import requests
|
|
|
|
import re, json
|
|
|
|
from datetime import datetime, timezone, timedelta
|
|
|
|
JST = timezone(timedelta(hours = 9))
|
|
|
|
class JPItem:
|
|
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 update(self):
|
|
try:
|
|
# 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))
|
|
except:
|
|
raise
|
|
|
|
j = j['items']
|
|
self.price = float(j['price'])
|
|
self.bids = j['bids']
|
|
self.start_date = datetime.fromisoformat(j['starttime']).replace(tzinfo = JST)
|
|
self.end_date = datetime.fromisoformat(j['endtime']).replace(tzinfo = JST)
|
|
self.last_checked = datetime.now(JST)
|
|
|
|
def price_jpy(self):
|
|
return f"¥{self.price:.2f}"
|
|
|
|
def price_aud(self, rate = 75.0):
|
|
return f"${self.price / rate:.2f}"
|