Skip to content

end-ichi/amazon-SC-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Amazon Supplement Comparison Bot

This tool will research the price per gram for a supplement on Amazon to allow you to choose a cheap option easily.

Setup

This is described for Linux. Some commands may need to be adapted for other operating systems.

Python Environment

python3.10 -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -r requirements.txt

Google API Key

You need a Google Cloud Console API key with the Generative Language API and Cloud Vision API enabled. If you're starting from scratch, follow these steps:

  • Go to aistudio.google.com and follow the instructions to set up an API key. Make sure to note down the API key.
  • This will create a project in Google Cloud Console and configure the API permissions for the Generative Language API.
  • Go to console.cloud.google.com and open the project you just created.
  • Go to API & Services > Enable APIs and services, search for cloud vision and enable the Cloud Vision API.
  • Go to API & Services > Credentials > the API key you created for Gemini, then select the Generative Language API and Cloud Vision API from the dropdown under API restrictions. Click Save.
cp config.yaml.template config.yaml
  • Enter your API key in the config file.

Chromium

source .venv/bin/activate
python -m app.main -b

Go to amazon.de in the Chromium window that opens, accept cookies, and log into your Amazon account. Close the browser.

Usage

source .venv/bin/activate
python -m app.main --help
python -m app.main -q 'query term' -m 10

This process will take a while, so keep the Chromium window alive and go do something else while it runs.

What it Does

We search for the query on Amazon and take the first m unique offers. For each, we first give the price, title, and description to an LLM to extract the necessary information (stage 1). If that fails, we pull the product images, OCR them, and try again with that additional information (stage 2). If that also fails, we give the LLM the images as image files instead of the OCR text (stage 3). The option -s [stage] lets you skip to that stage in each iteration. By default, we skip to stage 2.

After the information has been extracted and the price per gram computed, we sort the products by price per gram and output a table to console. The results are also saved to results.json.

Price

The price will depend on how much you use it. Google allots each user a free quota of API calls. If you exceed these, you will start being billed. I did a lot of queries while developing this and it cost me a grand total of 39 cents. So probably you'll save more money and time than you pay.

Disclaimer

This tool, being LLM-based, is not guaranteed to work. Sometimes the consumer deception is so blatant that the agent gets tricked. Feel free to adapt the system prompt as needed when you encounter issues.

The tool is a great help for comparing large numbers of products but in the end it is probably worth it to manually check the best couple results, especially if you're considering more criteria than just price.

Developer Notes

This project is based on selenium and pydantic-ai.

You can easily adapt this to use a different LLM provider or system prompt by editing app/find_data.py.

If Amazon decides to restructure their website, you may need to edit the selectors in app/main.py.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages