Giter VIP home page Giter VIP logo

price-alert's Introduction

Amazon price alert

Poll an Amazon sale page (or multiple pages) for a maximum price and send yourself an email if the price check passes.

Installation

Clone the repository. This code was written for python 3 (3.6.3), you should also have pip installed.

  • To install required libraries:

pip install --user -r requirements.txt

note that one the libraries used is the lxml library, which requires a couple of extra packages on Ubuntu:

[sudo] apt install libxml2-dev libxslt-dev

Configuration

Configuration is held in json format, config.json is used by default and has some configuration for reference, but a different file can be passed using the command line flags. you must set your email credentials. Required configuration:

  • email (dictionary) - this is the configuration for the email server and credentials to use for sending out the email.

    • smtp_url - smtp server to use (default: smtp.gmail.com:587)
    • user - the email address to be used for authentication
    • password - the password to be used for authentication (if you have 2FA set up on your account, take a look at app passwords)
  • base_url (string) - the base amazon url of the sales page, differs among the different variants of amazon.

  • xpath_selector (string) - the xpath selector of the element holding the price in the sale page, the default is true for all amazon variants that have been tested so far (default: //*[@id='priceblock_ourprice'])

  • items (array) - an array of items, each item should be an array as follows:

    [amazon_item_id_string, price_in_integer]

Running the script

$ ./price-alert.py --help
usage: price-alert.py [-h] [-c CONFIG] [-t POLL_INTERVAL]

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        Configuration file path
  -t POLL_INTERVAL, --poll-interval POLL_INTERVAL
                        Time in seconds between checks

when running without any arguments, the script will use config.json for configuration and the default polling interval of 30 seconds.

Other sale pages/email client

The script was tested on Amazon, so if you try running it on a different site make sure that xpath_selector is set correctly in the configuration json and that the price check itself is correct. The smtp client is configured for Gmail, so be sure to change it if you're using a different one.

TODO

  • add tests
  • add CI
  • override configuration via arguments/environment variables

price-alert's People

Contributors

c4tz avatar dependabot[bot] avatar eyalzek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

price-alert's Issues

Amazon expecting capcha

Just tried to run price-alert and I was getting the

Didn't find the 'price' element, trying again later

Now it looks like Amazon is wanting me to enter a Captcha.

Enter the characters you see below

Sorry, we just need to make sure you're not a robot. For best results, please make sure your browser is accepting cookies.

        <div class="a-section">

            <div class="a-box a-color-offset-background">
                <div class="a-box-inner a-padding-extra-large">

                    <form method="get" action="/errors/validateCaptcha" name="">
                        <input type=hidden name="amzn" value="0bg/HZ5wHJqUobhCg6n1/w==" /><input type=hidden name="amzn-r" value="&#047;dp&#047;B07KKBCXLY" />
                        <div class="a-row a-spacing-large">
                            <div class="a-box">
                                <div class="a-box-inner">
                                    <h4>Type the characters you see in this image:</h4>
                                    <!-- For automated access to price change or offer listing change events,
                                         please refer to the MWS Subscription API:
                                         https://developer.amazonservices.co.uk/gp/mws/api.html/276-5247872-0590350?ie=UTF8&section=subscriptions&group=subscriptions&version=latest

launching error

Is this readme / project deprecated?

apt install libxml2-dev libxslt-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libxslt1-dev' instead of 'libxslt-dev'
libxml2-dev is already the newest version (2.9.3+dfsg1-1ubuntu0.6).
libxslt1-dev is already the newest version (1.1.28-2.1ubuntu0.2).

pip3 install --user -r requirements.txt
Requirement already satisfied: requests==2.20.0 in /root/.local/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (2.20.0)
Requirement already satisfied: lxml==4.3.0 in /root/.local/lib/python3.7/site-packages (from -r requirements.txt (line 2)) (4.3.0)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /root/.local/lib/python3.7/site-packages (from requests==2.20.0->-r requirements.txt (line 1)) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /root/.local/lib/python3.7/site-packages (from requests==2.20.0->-r requirements.txt (line 1)) (2019.3.9)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /root/.local/lib/python3.7/site-packages (from requests==2.20.0->-r requirements.txt (line 1)) (1.24.3)
Requirement already satisfied: idna<2.8,>=2.5 in /root/.local/lib/python3.7/site-packages (from requests==2.20.0->-r requirements.txt (line 1)) (2.7)

./price-alert.py
Traceback (most recent call last):
  File "./price-alert.py", line 12, in <module>
    from lxml import html
ImportError: No module named 'lxml'

pip3 install lxml
Requirement already satisfied: lxml in /root/.local/lib/python3.7/site-packages (4.3.0)

gmail configuration (US)

Great little script! Just wanted to give a heads up for email config for use in gmail (US). I repeatedly received smtp related errors, even though other code examples seemed to match your code. The errors included "failed to login" (your logger code) as well as "smtplib.SMTPServerDisconnected: Connection unexpectedly closed", along with a few others.

Resolution: Going into gmail settings (https://myaccount.google.com/lesssecureapps) and turning this feature to 'ON'.

This may save future users some time if configuring with gmail (US) at the very least. Other than that, like the script and plan to modify it to fit my needs. Cheers!

JSON file item limit

This only works if the JSON file has 1-2 items maximum. If I try the code with more items (more product link IDs), then i get errors. Not sure what the solution is, or even what the error is saying.

Traceback (most recent call last):
File "price-alert.py", line 99, in
main()
File "price-alert.py", line 73, in main
config = get_config(args.config)
File "price-alert.py", line 57, in get_config
return json.loads(f.read())
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/init.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 380, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting , delimiter: line 12 column 9 (char 316)

Let me know if you have any idea, ill try to figure it out as well!

does it need proxy rotation for json items?

Congrats for the script. It's working , but after checking about 100 items it gives the message:
Didn't find the 'price' element.Trying again later.
and it's emailing me for every other item without reason for alert. However, it's all working again in a few hours , so I guess amazon just temporary blocked the ip address.
Any suggestions how to change the proxy between the JSON items?
Many Thanks

email by proxy

Hi! I have a problem using the script in my network, because the proxy isn't allowing to send the email. Could you help me to modify the script or tell me how to use a proxy settings?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.