thiagobruch / amazon_shopping_list_scrape

6 stars 1 forks source link

Amazon Shopping List Scraper

This project is based on (https://github.com/jtbnz/amazon_shopping_list/) by https://github.com/jtbnz

If you want to use as a Home Assistant Addon, use the link below:
https://github.com/thiagobruch/HA_Addons

The project scrapes the Amazon Shopping List page and add the items to the Home Assistant Shopping List (todo list) every 3 minutes (this can be changed in the file script.sh)

Important - Do not skip this step

You will need the Amazon Email and Password that you use to Login, the OTP Secret Key and the Home Assistant Webhook URL. Please find the instructions on how to get the OTP Secret Key and the Home Assistant Webhook URL:

How to get your OTP App Secret from Amazon :

If you don't have 2-step verification enable:

1 - Login to Amazon https://www.amazon.com/
2 - Go to Your Account => Login & Security and click on "Turn On" under 2-step verification
3 - Select the Authentication App
4 - Click on "Can't scan the barcode" and save the Key (13 sets of 4 characters each)
5 - Remove the spaces of the Key (you will have something like this "ASDMASDFMSKDMKSFMKLASDDADABB6JNRNF7WFEHQW23H238R7843")

If you already have 2-step verification enable:

1 - Login to Amazon https://www.amazon.com/
2 - Go to Your Account => Login & Security and click on "Manage" under 2-step verification
3 - Under Authenticator App, click on Add New App
4 - Click on "Can't scan the barcode" and save the Key (13 sets of 4 characters each)
5 - Remove the spaces of the Key (you will have something like this "ASDMASDFMSKDMKSFMKLASDDADABB6JNRNF7WFEHQW23H238R7843")

How to get the Home Assistant Webhook URL:

1 - Go to your Home Assistant interface and go to Settings, Automations & Scenes, Automations
2 - Click on "+ Create Automation" and select "Create new automation"
3 - Click on Add Trigger and select Webhook
4 - Click on the copy symbol on the right to get the URL and save it (example: http://homeassistant.local:8123/api/webhook/-hA_THs-Yr5dfasnnkjfsdfsa)
You'll have to use the internal URL
5 - Switch the view to YAML (three dots on the top right - Edit in YAML)
6 - Delete the line "action: []" and aste the following code:

Once you have the information above, you can use two methods:
1 - Docker Image already built
2 - Create your own Docker Image

Docker Image Instructions:

Pull Image(around 800MB):

docker pull thiagobruch/amazon-scrape-tb

Start Image:

docker run -d \
  --name amazon-scraper \
  -e AMZ_LOGIN='<YOUR_AMAZON_EMAIL>' \ # your email address used to login at amazon in this format 'email@email.com' including single quotes.
  -e AMZ_PASS='<YOUR_AMAZON_PASSORD>' \ # your password used to login at amazon in this format 'mypassword1234' including single quotes.
  -e AMZ_SECRET='<YOUR_OTP_APP_SECRET>' \ # your OTP App Secret in this format 'mypassword1234' including single quotes. More instructions above.
  -e HA_WEBHOOK_URL='<HOME_ASSISTANT_WEBHOOK_URL' \ # your Home Assistant Webhook URL including single quotes. More instructions above.
  -e Amazon_Sign_in_URL='<Amazon_SIGNIN_URL>' \ # The Sign-In Page for your amazon Account. More instructions on the address below
  -e Amazon_Shopping_List_Page='<Amazon_SHOPPING_LIST_URL>' \ # The Shopping list Page for your amazon Account. More instructions on the address below
  -e polling_interval='180' \ # The pooling interval in seconds. We recommend using 180 seconds or more.
  -e delete_after_download=true \ # When set to true, the items will be delete from Amazon Shopping list once they are added to HA.
  thiagobruch/amazon-scrape-tb

Create your Image Instructions:

1 - Save all the file in a single directory
2 - Run the following command:

docker build -t amazon-scrape-tb .

3 - It will take a while to create the image (around 850MB)
4 - Once it is completed, run the docker run command with the variables to start the container:

docker run -d \
  --name amazon-scraper \
  -e AMZ_LOGIN='<YOUR_AMAZON_EMAIL>' \ # your email address used to login at amazon in this format 'email@email.com' including single quotes.
  -e AMZ_PASS='<YOUR_AMAZON_PASSORD>' \ # your password used to login at amazon in this format 'mypassword1234' including single quotes.
  -e AMZ_SECRET='<YOUR_OTP_APP_SECRET>' \ # your OTP App Secret in this format 'mypassword1234' including single quotes. More instructions below.
  -e HA_WEBHOOK_URL='<HOME_ASSISTANT_WEBHOOK_URL' \ # your Home Assistant Webhook URL including single quotes. More instructions below.
  -e Amazon_Sign_in_URL='<Amazon_SIGNIN_URL>' \ # The Sign-In Page for your amazon Account. More instructions on the address below
  -e Amazon_Shopping_List_Page='<Amazon_SHOPPING_LIST_URL>' \ # The Shopping list Page for your amazon Account. More instructions on the address below
  -e polling_interval='180' \ # The pooling interval in seconds. We recommend using 180 seconds or more.
  -e delete_after_download=true \ # When set to true, the items will be delete from Amazon Shopping list once they are added to HA.
  amazon-scrape-tb

* If you are not in the US and use Amazon in a different country, change the URLs below:

* Extra - Clear Alexa Shopping List

Because this is a one way sync (from Amazon Shopping List to Home Assistant), I have an automation that clear Amazon Shopping list every night at midnight. Here is the Automation in YAML:


description: ""
mode: single
trigger:
  - platform: time
    at: "00:00:00"
condition: []
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.01
    target:
      entity_id: media_player.my_alexa
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - service: media_player.play_media
    data:
      media_content_type: custom
      media_content_id: "clear my shopping list"
      enqueue: play
    target:
      entity_id: media_player.my_alexa
    enabled: true
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
    enabled: true
  - service: media_player.play_media
    data:
      media_content_type: custom
      media_content_id: "yes"
      enqueue: play
    target:
      entity_id: media_player.my_alexa
    enabled: true