This tool will research the price per gram for a supplement on Amazon to allow you to choose a cheap option easily.
This is described for Linux. Some commands may need to be adapted for other operating systems.
python3.10 -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -r requirements.txtYou 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 forcloud visionand 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 underAPI restrictions. ClickSave.
cp config.yaml.template config.yaml- Enter your API key in the config file.
source .venv/bin/activate
python -m app.main -bGo to amazon.de in the Chromium window that opens, accept cookies, and log into your Amazon account. Close the browser.
source .venv/bin/activate
python -m app.main --help
python -m app.main -q 'query term' -m 10This process will take a while, so keep the Chromium window alive and go do something else while it runs.
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.
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.
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.
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.