Are you all exercising? Ring Fit Adventure, which is perfect for withdrawal, has recently been released by Nintendo! !! I also wanted to buy it, but it seems to be out of stock and it's painful. Having said that, it's annoying to buy at a high price from resellers at Mercari or Yahoo Auction, so I tried my best to buy it through the regular route.
When I googled various things, I heard from mail order that the products arrived and the inventory was restored. However, I can't stick to it in front of the mail-order site all the time, so I was wondering if I could notify me when the inventory was restored. So, using this kind of convenient site, I made an app that notifies you by Line if the inventory is restored here.
Click here for deliverables! https://github.com/aitaro/inventory-notification
By the way, if you change the item code, you can use it with other products.
To be honest, any language is fine. I personally like Ruby, but somehow I chose Python. Development is done locally, but due to the nature of inventory notification, let's develop with the idea of deploying somewhere.
.
├── README.md
├── main.py
└── requirements.txt
requirements.txt
line-bot-sdk
selenium
chromedriver-binary
It's basically 2 steps.
Deploy this to a suitable server. (This time heroku)
There are two ways to scrape, one is to use selenium and the other is to use beautifulsoup4, but since this site goes to get inventory information of other sites after accessing it, we use selenium that reproduces the behavior of the browser as it is. In addition, line creates a bot from here and issues an access token. GOOGLE_CHROME_SHIM
in the code is the location of the chrome executable.
main.py
from linebot import LineBotApi
from linebot.models import TextSendMessage
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import chromedriver_binary
import re
import time
import os
#Inventory information acquisition
#Ring Fit Adventure
item_id = '4902370543278'
# item_id = '4988013097025'
#Launch browser
options = Options()
options.binary_location = os.getenv('GOOGLE_CHROME_SHIM')
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
# net-Access zaiko
url = 'https://www.net-zaiko.com/item/' + item_id
driver.get(url)
time.sleep(10)
targetElements = driver.find_elements_by_css_selector("#sl0 .siSa,.siSb,.siSc,.siSd,.siSe")
title = driver.find_element_by_id("itmH0").text
#Check if there is stock at each online shop
flag = False
for el in targetElements:
#Amazon is excluded because it comes up with make-up
pattern = r'Amazon\.co\.jp'
result = re.search(pattern, el.text)
if not result:
flag = True
print('In stock')
print(el.text)
print(title)
#Exit browser
driver.quit()
#Notify Line
line_bot_api = LineBotApi(os.getenv('LINE_CHANNEL_ACCESS_TOKEN'))
if flag:
messages = TextSendMessage(text=f"{title}In stock!\n Please access from here{url}")
line_bot_api.broadcast(messages=messages)
--Since the notation of in stock fluctuated depending on the site, it is judged that it is in stock with the green frame (siSa ~ siSe). --Amazon is excluded because the make-up rip-off scam is terrible
Since chrome was included and it was necessary to be able to execute it regularly, I examined various things under that condition, but since it seemed that heroku could go for free, I chose heroku. I will omit how to make it in the application with heroku, but you can put the heroku scheduler with add-on and chrome and chrome drive with buildpack. See here.
I made it for about 2 hours. I can't buy it yet. I want it soon. Do scraping as long as it doesn't bother you.
Recommended Posts