CEX UK is a second-hand shop where you can buy video games, movies, various electronic products etc.
The initial goal of this project was to add a cron job which would check the CEX stock and notify me when
some specific games are available in my local store.
stock_check.py
- a simple Python script used to check CEX UK API to verify whether the specified items are in the stock.
load_stores.py
- maps CEX store ID to store name and writes mapped values to the config/stores.yaml
file. By default the stores.yaml
is provided, however you might want to run make load-stores
if the store you are looking for isn't included.
Additionally, it's possible to configure this script to send the stock check results to a specified email address. Any contributions are welcome!
The configuration file - config/checker.yaml
:
items
- An array of item titles that will be used to make a stock check.request_delay
- Request delay in seconds between HTTP GET requests. By default is set to 2 seconds.store_ids
- Checkconfig/stores.yaml
for CEX store IDs, alternatively you can find store ID by making a call to CEX website and making a refined search by selecting a specific store's stock.
Example:
After selectingLondon W1 Tottenham Crt Rd
produces the following URL:
https://uk.webuy.com/search/index.php?stext=crystal+castles+III§ion=&rad_which_stock=3&refinebystore=1
The store ID is defined afterrefinebystore
, in this example it's1
.
The following configuration values aren't set:
proceed_prompt_enabled
- If set totrue
will disable the prompt before continuing with the stock check. By default is set to true.send_email_enabled
- If set totrue
will send a message containing the stock check result to the specified email address. By default is set to false.email
- The message will be sent from this email address.email_pass
- The password for the email address.to_email
- The message will be sent to this email address.smtp_host
- The SMTP server host.smtp_port
- The SMTP port number.
- Clone the project
- Update the
config/checker.yaml
file - Install requirements by running
make requirements
- Run the script
make run
- Run
make docker-run-local
to build a docker image locally and to run it. - Alternatively, it's possible to use prebuilt
martinsirbe/cex-stock-checker
docker image by runningmake docker-run CUSTOM_CONFIG=config/checker.yaml
, whereCUSTOM_CONFIG
points to the custom configuration file relative to the root of this project.
- To map Store IDs to store names, simply run
make load-stores
. This will create a newconfig/stores.yaml
file, which will contain the mapping between the CEX store ID and name, e.g.1: London W1 Tottenham Crt Rd
.
- Run
crontab -e
and add following line, whereubuntu
is your home directory name:
30 10 * * * cd /home/ubuntu/path/to/cex-stock-checker/ && python3 stock_check.py
The above example would execute the script every day at 10:30. You can use following CRON generator to run script at your own specified time - http://crontab-generator.org/
This project is licensed under the MIT License - see the LICENSE.md file for details.
- Fork the repository github.com/martinsirbe/cex-stock-checker
- Create your feature branch:
git checkout -b my-feature-branch
- Commit your changes:
git commit -m 'Add ...'
- Push to the branch.
git push origin my-feature-branch
- Create a new pull request and select the
cex-stock-checker
master branch as the base.