Last active
November 23, 2021 20:38
-
-
Save jkctech/0d3049626799d9bde49fe28d1432db89 to your computer and use it in GitHub Desktop.
Scraper for Archonia stock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
# ========== SETTINGS ========== | |
str_available = "Beschikbaar!" | |
str_unavailable = "Niet beschikbaar!" | |
str_preorder = "Pre-order!" | |
str_unknown = "Onbekend" | |
filename = "links.txt" | |
pushover_enabled = True | |
pushover_apikey = "" | |
pushover_userkey = "" | |
# ========== /SETTINGS ========== | |
# Pushover util | |
def push(user_key, api_key, message, title=None, priority=0, url=None): | |
endpoint = "https://api.pushover.net/1/messages.json" | |
data = { | |
"token": api_key, | |
"user": user_key, | |
"message": message, | |
"priority": priority | |
} | |
if url != None: | |
data['url'] = url | |
if title != None: | |
data['title'] = title | |
req = requests.post(endpoint, params=data) | |
return (req.status_code == 200, req.text) | |
# Stores availability | |
available = {} | |
# Read all links from file | |
with open(filename) as file: | |
lines = file.readlines() | |
lines = [line.rstrip() for line in lines] | |
# Loop over lines | |
for line in lines: | |
raw = requests.get(line).text | |
# Ik hoop dat dit zo werkt, nog nooit zo gebruikt | |
if "In stock now!" in raw: | |
status = str_available | |
elif 'Pre-order <i class="fa fa-shopping-cart m-l-xs" aria-hidden="true"></i>' in raw: | |
status = str_preorder | |
elif "Out of stock": | |
status = str_unavailable | |
else: | |
status = str_unknown | |
# Get product info | |
productid = raw.split('Product Code')[1].split('>')[3].split('<')[0].upper().strip() | |
name = raw.split('"name": "')[1].split('"')[0] | |
# Add to list | |
available[productid] = (status, name, line) | |
# Print all items | |
for item in available.keys(): | |
print("[{}] {}: {}".format(item, available[item][1], available[item][0])) | |
# If available, send message | |
if pushover_enabled and available[item][0] in [str_available, str_preorder]: | |
# Variables | |
title = "[{}] {}".format(available[item][0], available[item][1]) | |
message = "[{}] {} in stock!".format(item, available[item][1]) | |
# Acutally send push | |
p = push(pushover_userkey, pushover_apikey, message, title=title, priority=0, url=available[item][2]) | |
# Debug | |
if p[0] == False: | |
print("Could not send push notification: " + p[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://www.archonia.com/en-us/product/120397/gto-14-days-in-shonan-manga-vol-01-gn | |
https://www.archonia.com/en-us/product/375502/shaman-king-omnibus-vol-01-gn-manga | |
https://www.archonia.com/en-us/product/419074/chainsaw-man-vol-10-gn-manga |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment