Modular bot for checking and purchasing stock in online stores.
- Table of Contents
- Introduction
- Motivation
- Features
- Requirements
- Usage
- File Structure
- Development Guide
- ToDos
This project implements a bot to check the availability of products online and pyurchase them. It uses a different module for each website to allow more flexibility when developing for a specific website. It also implements different alert modules to perform different actions when there is a change in the stock of a product or when it has been purchased.
I developed this bot to be able to buy products that are impossible to buy in other circumstances due to low stock or scalpers using the bots to buy the stock and then resell it to make a profit. For this reason, this bot has been developed to only buy 1 unit of a specific product.
- Highly flexibile
- Highly modular
- Highly customizable
- Easy integration with different websites
- Easy integration with different alerts
- Can search for different products at the same time
- Allows several actions, like
check
(check availability) orbuy
(buy product). - Only buys 1 unit of a specific product
- Since it uses Selenium, it can execute JavaScript, which ensures that it will be able to load most web pages.
- You can specify the amount of time to wait until the stock is checked again.
- Python
- PIP
- Selenium
- Geckodriver
To access websites, this script uses Selenium. To install it, you can follow this guide. In essence, you just need to install Selenium using the following command:
pip install -U selenium
Then, download the geckodriver (which is the one used by this project) and put it in your PATH.
Make sure you comply with the Requirements.
Download this repository. In the file called globals.py
you have to set your variables:
time_interval
: specifies the number of seconds to wait until checking the stock again.webmodules
: specifies the webmodule to use based on the start of the url. Do not change this unless you develop a new module.alertmodules
: specifies the alertmodule to use based on the specified action. Do not change this unless you develop a new module.productlist
: List of URLs to check. Depending on the domain name, the specific module will be called by the bot. The list is made up of tuples:- The first element is an index that identifies a specific product. This is used to check multiple products at once.
- The second element is a URL where the specific product is sold.
- The third element of the tuple is the action to perform. The 'buy' action buys the product, and 'check' action only checks if the specific product is in stock. If a specific product is purchased on one domain, that product will not be purchased or checked on any of the other domains in the list.
An example of globals.py
would be:
def init_globals():
global time_interval
time_interval = 5 * 60 # wait for 5 minutes
global webmodules
webmodules = {
'https://www.example1': 'example1',
'https://www.example2': 'example2',
'https://www.example3': 'example3'
}
global alertmodules
alertmodules = {
'check': 'simple_print',
'buy': 'open_url'
}
global product_list
product_list = [
(0, 'https://www.example1.com/product0', 'check'),
(0, 'https://www.example2.com/product0', 'buy'),
(0, 'https://www.example3.net/product0', 'check'),
(1, 'https://www.example1.de/product1', 'buy'),
(1, 'https://www.example3.com/product1', 'buy'),
(2, 'https://www.example2.com/product2', 'check')
]
# Important project components
.
├── alert_modules - # Modules used to notify about stock changes
│ ├── __init__.py - # Imports all modules found on this folder
│ ├── open_url.py - # Opens a URL with the system default browser
│ └── simple_print.py - # Prints all important information
├── ascii.py - # Startup ASCII art
├── globals.py - # User specified variables
├── img - # README images
├── sbf.py - # Main script
├── web_modules - # Modules used depending on the webpage
│ ├── __init__.py - # Imports all modules found on this folder
│ └── ... - # Modules for different websites
└── web_utilities - # Some uilities
└── browser.py - # Class used to manage a selenium webdriver
Guide on how to develop different parts of the bot:
To develop a new website module follow these steps:
- Find a website that you want to develop a module for.
- Add the beginning of its URL to
webmodules
dictionary insideglobals.py
. The value you specify in this dictionary element must be the name of the module you will create. - Create a file with the same name as the value of the dictionary element created in step 2 inside the folder
web_modules
. - Create a function called
check
(check stock availability),buy
(buy product) and any additional action desired. - Develop these functions. They must return a boolean.
- You can now freely add the URL of the product to
productlist
insideglobals.py
. Your module will be automatically called.
To develop a new alert module follow these steps:
- Think of an alert behaviour that you want to develop.
- Add the action that will use this module to
alertmodules
dictionary insideglobals.py
. The value you specify in this dictionary element must be the name of the module you will create. - Create a file with the same name as the value of the dictionary element created in step 2 inside the folder
alert_modules
. - Create a function called
check
(check stock availability),buy
(buy product) and any additional action desired. - Develop these functions. They can have different behaviours based on the state of the stock.
- You can now freely use the action tied to your alert. Specifying that action to a product in
productlist
insideglobals.py
will call your alert module if the action returned successfully.
To develop a new action follow these steps:
- Think of an action that you want the bot to perform with specific URLs.
- Add the action to
alertmodules
dictionary insideglobals.py
and specify a particular alert module that will be called when your action has been acomplished. - Create a function for your action in any module you want from
alert_modules
andweb_modules
. The methods must have the same name as the action. - Develop these function.
- You can now freely add the action to any product found in
productlist
insideglobals.py
. Your action methods will be automatically called.
- Develop the
buy
action for all modules. - Develop new modules for more websites.