[PYTHON] The story of wanting to buy Ring Fit Adventure

background

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.

What i did

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.

Environment

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.

Folder structure

.
├── README.md
├── main.py
└── requirements.txt

requirements.txt


line-bot-sdk
selenium
chromedriver-binary

Implementation

It's basically 2 steps.

  1. Scraping from net-zaiko.com
  2. Send to line

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)

Ingenuity

--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

Deploy

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.

Impressions

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

The story of wanting to buy Ring Fit Adventure
Behind the Ring Fit Adventure arrival bot to eradicate resellers
The story of trying to reconnect the client
[Python] Try to graph from the image of Ring Fit [OCR]
The story of adding MeCab to ubuntu 16.04
The story of pep8 changing to pycodestyle
The story of wanting to buy Ring Fit Adventure
[Python] Try to create ring fit data using Amazon Textract [OCR] (Try code review with Code Guru)
Behind the Ring Fit Adventure arrival bot to eradicate resellers
The story of moving from Pipenv to Poetry
The story of sys.path.append ()
The story of using circleci to build manylinux wheels
The story of building Zabbix 4.4
[Apache] The story of prefork
The story of introducing jedi (python auto-completion package) to emacs
The story of copying data from S3 to Google's TeamDrive
After all, the story of returning from Linux to Windows
Now in Singapore The story of creating a LineBot and wanting to do a memorable job
The story that the version of python 3.7.7 was not adapted to Heroku
The story of Python and the story of NaN
The story of not being able to run pygame with pycharm
The story of participating in AtCoder
A story that struggled to handle the Python package of PocketSphinx
Test the goodness of fit of the distribution
The story of the "hole" in the file
[Pythonista] The story of making an action to copy selected text
The story of remounting the application server
Supplement to the explanation of vscode
The story of writing a program
The story of failing to update "calendar.day_abbr" on the admin screen of django
zoom I tried to quantify the degree of excitement of the story at the meeting
I tried to extract and illustrate the stage of the story using COTOHA
I tried the common story of using Deep Learning to predict the Nikkei 225
The story of trying to push SSH_AUTH_SOCK obsolete on screen with LD_PRELOAD
The story of an error in PyOCR
Script to change the description of fasta
10 methods to improve the accuracy of BERT
How to check the version of Django
The story of verifying the open data of COVID-19
The story of making Python an exe
The story of making an immutable mold
The story of manipulating python global variables
The story of trying deep3d and losing
The story of blackjack A processing (python)
The story of IPv6 address that I want to keep at a minimum
The story of switching the Azure App Service web system from Windows to Linux
The story of making soracom_exporter (I tried to monitor SORACOM Air with Prometheus)
A story of a high school graduate technician trying to predict the survival of the Titanic
How to calculate the volatility of a brand
The story of doing deep learning with TPU
How to find the area of the Voronoi diagram
The story of low learning costs for Python
Combinatorial optimization to find the hand of "Millijan"
Setting to output the log of cron execution
The inaccuracy of Tensorflow was due to log (0)
Set the range of active strips to the preview range
The story of making the Mel Icon Generator version2
I tried to touch the API of ebay
I tried to correct the keystone of the image
Change the decimal point of logging from, to.
Image processing? The story of starting Python for
The story of finding the optimal n in N fist
Story of trying to use tensorboard with pytorch