Behind the Ring Fit Adventure arrival bot to eradicate resellers

2020/01/11

Ringfit Adventure arrival bot has been frozen, so it has been renewed. We look forward to your continued support of Price arrival dolphin @ Ring Fit Adventure.

Overview

Notify when Ring Fit Adventure arrives at Amazon at a fixed price Ringfit Adventure arrival bot I made. I will introduce the back side of this bot. Eradicate resellers.

Image from iOS.jpeg

background

Ring Fit Adventure is very popular. It has been in short supply since it was released. This shortage is due to bulk purchases aimed at resale by resellers. In fact, there are hundreds of resales on Amazon at a price (about 12000 yen) that greatly exceeds the list price (8778 yen).

In order to buy at a fixed price without losing to resellers, it is necessary to pop in as soon as possible after arrival. Therefore, I decided to create a function to notify the arrival of ring fits at a fixed price. First of all, I made it for the purpose of getting a ring fit.

On the other hand, I also thought that by exposing this function, it would be possible to eradicate resellers. It is difficult to eliminate the existence of resellers. But with this feature, you can overcome the situation where you have to buy from a reseller. By providing a place where general purchasers can fight on the same level as resellers, we thought that it would be unnecessary to buy from resellers, and as a result, it would lead to eradication of resellers.

Santa Claus who want to give a ring fit as a Christmas present. Children who want to hold a New Year's gift and buy a ring fit. I fight with the power of IT.

Eradicate resellers.

Purpose

--I buy Ring Fit Adventure --Providing opportunities for Santa Claus and children to buy Ring Fit Adventure --Eradicate resellers

System configuration

I will explain the system configuration to eradicate resellers.

リングフィットqiita.png

The bot program runs on AWS EC2. EC2 has a python script and a crontab configuration file deployed.

flow

I will explain the flow to eradicate resellers.

System job flow

  1. Every minute, cron runs a python script that does the following:
  2. selenium → chrome | Go to the Amazon Ring Fit Adventure product page.
  3. selenium | parse the get html to get the price of the ring fit.
  4. python | Determine if the ring fit price is the list price.
  5. selenium → chrome | If the price is fixed, log in to twitter and tweet.

User usage flow

  1. Follow the Ring Fit Adventure arrival bot.
  2. Turn notifications on.
  3. You will receive a notification of the tweet notifying you of the arrival.
  4. Access amazon as soon as possible and click on the ring fit with a list price of 8778 yen.
  5. You will receive a ring fit in a few days.

Source code

Introducing the source code to eradicate resellers.

python & selenium & chrome

amazon.py


from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import json
import urllib.request
import datetime
import pytz

#URL of the Ringfit product page
url = 'https://www.amazon.co.jp/%E4%BB%BB%E5%A4%A9%E5%A0%82-%E3%83%AA%E3%83%B3%E3%82%B0%E3%83%95%E3%82%A3%E3%83%83%E3%83%88-%E3%82%A2%E3%83%89%E3%83%99%E3%83%B3%E3%83%81%E3%83%A3%E3%83%BC-Switch/dp/B07XV8VSZT/ref=sr_1_1?__mk_ja_JP=%E3%82%AB%E3%82%BF%E3%82%AB%E3%83%8A&keywords=%E3%83%AA%E3%83%B3%E3%82%B0%E3%83%95%E3%82%A3%E3%83%83%E3%83%88&qid=1575977457&sr=8-1'

#Launch chrome from selenium and access the ring fit product page
options = webdriver.ChromeOptions()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
driver.get(url)

#Function to tweet
def tweet(message):
    #twitter account
    account = 'ringfit_hoshii'
    password = 'hogehoge'
    #Start selenium
    options = webdriver.ChromeOptions()
    options.add_argument('--headless')
    driver = webdriver.Chrome(options=options)
    driver.set_window_size(height=877, width=1440)
    #Open login page
    driver.get('https://twitter.com/login/')
    time.sleep(3)  #Stop working
    #Enter account
    element_account = driver.find_element_by_class_name("js-username-field")
    element_account.send_keys(account)
    #Enter password
    element_pass = driver.find_element_by_class_name("js-password-field")
    element_pass.send_keys(password)
    #Click the login button
    element_login = driver.find_element_by_xpath('//*[@id="page-container"]/div/div[1]/form/div[2]/button')
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    element_login.click()
    #Tweet
    time.sleep(3)
    driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div/main/div/div/div/div[1]/div/div[2]/div[2]/div[1]/div/div/div[2]/div[1]/div/div/div/div/div/div/div/div[1]/div[1]/div/div/div/div[2]/div/div/div/div').send_keys(message)
    # time.sleep(1)
    driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div/main/div/div/div/div[1]/div/div[2]/div[2]/div[1]/div/div/div[2]/div[2]/div/div/div[2]/div[3]').click()
    #Sleep to wait for the tweet to be sent
    time.sleep(2)
    driver.quit()
    return

#Function to get price & price judgment from Amazon's ring fit product page
def get_price(xpath):
    price1 = driver.find_element_by_xpath(xpath)
    p1str = price1.text[1:]
    p1int = int(p1str.replace(',',''))
    now = datetime.datetime.now(pytz.timezone('Asia/Tokyo'))
    message2 = "[In Stock] Ring Fit Adventure" + str(p1int) + "Sold in yen!" + " Amazon URL: " + url + " datetime: " + str(now)
    #List price judgment
    if p1int > 9000 or p1int < 5000:
        return
    tweet(message2)
    return

#There are several xpath appearance patterns on the RingFit product page, so try to get the price for those patterns.
xpaths = [
'//*[@id="unqualifiedBuyBox"]/div/div[1]/span',
'//*[@id="priceblock_ourprice"]'
]
for xpath in xpaths:
    get_price(xpath)

driver.quit()

For executing tweets on selenium, I referred to here. The element acquisition by xpath was done by the same method as here.

crontab

cron.conf


#The chrome driver referenced by selenium/home/ec2-user/Since it is in bin, add it to path
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ec2-user/.local/bin:/home/ec2-user/bin
#Run python script every minute
* * * * * python3 /home/ec2-user/ringfit/amazon.py

Initial setting & deployment

Describes server settings and deployments to eradicate resellers.

Server (EC2) initial settings


#Download and install the required resources
sudo yum -y update
sudo yum -y install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
#Download the driver for the chrome version.
#Version confirmation command
# yum info google-chrome-stable
wget https://chromedriver.storage.googleapis.com/78.0.3904.105/chromedriver_linux64.zip
unzip chromedriver_linux64.zip -d bin/
sudo yum -y install python3
sudo pip3 install Selenium
sudo pip3 install pytz
sudo yum -y install ipa-gothic-fonts ipa-mincho-fonts ipa-pgothic-fonts ipa-pmincho-fonts

Deploy

Deploy ʻamazon.pyandcron.conf(omitted). Let's say you deployed to/ home / ec2-user / ringfit`.

cron settings


#Deploy destination
deploy_dir="/home/ec2-user/ringfit"

#crontab settings (reset and then cron.conf is being read)
crontab -r
crontab -u ec2-user ${deploy_dir}/cron.conf

motion

You will receive tweets like this every minute during arrival.

スクリーンショット 2019-12-24 0.24.27.png

Q&A

Why via selenium?

Amazon Since it is played when accessed from the curl command or python, I started chrome with selenium and took the method of accessing with the same procedure as a general user.

twitter I got a twitter developer account, but for some reason I didn't have permission to create an app. When I went around, there was a description that I could register a phone number in my twitter account, but for some reason I could not register a phone number, ... Give up and launch chrome with selenium, the following is abbreviated.

Is it a useful function for resellers?

That's right. However, I think that resellers have such a function on their own. The significance of this bot is to allow general buyers to stand on the same ground as resellers.

Improvement points

――Price acquisition from Amazon is really suitable xpath, so I would like to think of a more robust method. ――Since the cost of EC2 is high, I would like to move to Lambda etc. that can be operated within the free tier. --I want to use the twitter API properly.

Real intention

――I want to make some income by making the link attached to the tweet an affiliate link. At least about AWS fee ... ――I thought I would go about 1000 followers in no time. I advertised on multiple accounts and facebook. I searched for "Ringfit not for sale" and "I want a ringfit" and opened it with manual likes every day. As a result, it does not increase. I don't go 50. It doesn't increase at all. why? If you can buy a ring fit, you will be unfollowed because the bot is already obsolete. The annoyance of the once-minute notification is boosting. On the flip side, I'm happy that users are buying Ringfits properly, but I'm far from the goal of providing this feature to many people and eradicating resellers. ――In order to increase followers, we also considered announcements of products other than ring fit, but for example, just because you want ring fit does not mean that you want AirPods, and I think that announcements of products that you are not interested in will only be noise. I did.

in conclusion

Until the end Thank you for reading. It was my first Qiita post. I will continue to write articles (a little more seriously), so I look forward to working with you.

If you haven't got Ring Fit Adventure yet, please use it if you like ↓ Ringfit Adventure arrival bot

Ring Fit Adventure that I could buy at a fixed price ↓ EL6HPVZVAAAN7zX.jpeg

Voice of gratitude ↓ Image from iOS (1).jpeg

Recommended Posts

Behind the Ring Fit Adventure arrival bot to eradicate resellers
The story of wanting to buy Ring Fit Adventure
[Python] Try to graph from the image of Ring Fit [OCR]
Record your Ring Fit Adventure with OCR