Skip to content

Instantly share code, notes, and snippets.

@plallin
Created August 3, 2020 13:15
Show Gist options
  • Save plallin/52109acd494b7b892a755a15326eaa79 to your computer and use it in GitHub Desktop.
Save plallin/52109acd494b7b892a755a15326eaa79 to your computer and use it in GitHub Desktop.
import requests
import json
import subprocess
from collections import namedtuple
import time
PieceOfArts = namedtuple('PieceOfArt', ['id', 'variant'])
arts = {
'robust_statue': PieceOfArts('3865006808', '3072656478'),
# 'rock-head': PieceOfArts('3120787553', '3618052157'),
# 'tremendous': PieceOfArts('3454623694', '3832379816'),
# 'wild_right_half': PieceOfArts('3930465220', '2526089018'),
}
def send_notification(notif_message):
print('***************')
print(notif_message)
print('***************')
subprocess.Popen(['notify-send', notif_message])
return
def nookazon_request(art_id):
url=f'https://nookazon.com/api/listings?item={art_id}&auction=false'
headers = {
'authority': 'nookazon.com',
'access-control-allow-origin': '*',
'accept': 'application/json',
'dnt': '1',
'content-type': 'application/json',
'accept-language': 'en-US',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://nookazon.com/product/3867434973'
}
return requests.get(url, headers = headers)
def find_me_art(list_of_arts, already_found = []):
for art_name, art_data in list_of_arts.items():
print(f'checking {art_name} (i={art_data.id}, v={art_data.variant})')
# send request and extract listings
r = nookazon_request(art_data.id)
items = json.loads(r.text)['listings']
# Check for the good stuff
for item in items:
if item['variant_id'] == art_data.variant:
if item['offer_bells']:
itemid = item['id']
if not itemid in already_found:
notif_message = f'new listing for {art_name}: https://nookazon.com/listing/{itemid}'
send_notification(notif_message)
already_found.append(itemid)
# Don't DDOS the Nookazon
time.sleep(5)
return already_found
found = []
while True:
found = find_me_art(arts, found)
time.sleep(30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment