Skip to main content

Monitors prices of Amazon products via Product Advertising API

Project description

Build Status codecov.io Requirements Status Stories in Ready

django-amazon-price-monitor

Monitors prices of Amazon products via Product Advertising API.

Basic structure

This is a reusable Django app that can be plugged into your project. It consists basically of this parts:

  • Models

  • Frontend components

  • Angular Frontend API

  • Amazon API component

Models

  • Product

    • representation of an Amazon product

  • Price

    • representation of a price of an Amazon product at a specific time

  • Subscription

    • subscribe to a product at a specific price with an email notification

Frontend components

The frontend displays all subscribed products with additional information and some graphs for price history.

We currently have 2 implementations, the (old) static one and the (new) one with AngularJS. After some issues have been resolved in the AngularJS implementation, we will remove the old static one.

The components feature the followung

  • static version

    • list products

    • add subscriptions

    • delete subscriptions

  • AngularJS version

    • list products

    • show product details

    • show product price graphs

    • add subscriptions

    • adjust subscription price value

    • delete subscriptions

Angular Frontend API

Simply the API consumed by AngularJS, based on Django REST Framework.

Amazon API component

Fetches product information from Amazon Product Advertising API through several tasks powered by Celery and weaves the data into the models.

License

This software is licensed with the MIT license. So feel free to do with it whatever you like.

Setup

Prerequisites

  • Python 3.3, 3.4

  • see setup.py

Included angular libraries

Basic setup

Add the following apps to INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'price_monitor',
    'price_monitor.product_advertising_api',
    'rest_framework',
)

Then migrate:

python manage.py migrate

Adjust the settings appropiately, see next chapter.

Settings

The values of the following displayed settings are their default values. If the value is ‘…’ then there is no default value.

Must have settings

The following settings are absolutely necessary to the price monitor running, please set them:

Celery

You need to have a broker and a result backend set.

BROKER_URL = ...
CELERY_RESULT_BACKEND = ...

# some additional settings
CELERY_ACCEPT_CONTENT = ['pickle', 'json']
CELERY_CHORD_PROPAGATES = True
Rest-Framework

We use Rest-Framework for Angular frontend:

REST_FRAMEWORK = {
    'PAGINATE_BY': 50,
    'PAGINATE_BY_PARAM': 'page_size',
    'MAX_PAGINATE_BY': 100,
}
AWS and Product Advertising API credentials
# your Amazon Web Services access key id
PRICE_MONITOR_AWS_ACCESS_KEY_ID = '...'

# your Amazon Web Services secret access key
PRICE_MONITOR_AWS_SECRET_ACCESS_KEY = '...'

# the region endpoint you want to use.
# Typically the country you'll run the price monitor in.
# possible values: CA, CN, DE, ES, FR, IT, JP, UK, US
PRICE_MONITOR_AMAZON_PRODUCT_API_REGION = '...'

# the assoc tag of the Amazon Product Advertising API
PRICE_MONITOR_AMAZON_PRODUCT_API_ASSOC_TAG = '...'
Images protocol and domain
# if to use the HTTPS URLs for Amazon images.
# if you're running the monitor on SSL, set this to True
# INFO:
#  Product images are served directly from Amazon.
#  This is a restriction when using the Amazon Product Advertising API
PRICE_MONITOR_IMAGES_USE_SSL = True

# domain to use for image serving.
# typically analog to the api region following the URL pattern
#  https://images-<REGION>.ssl-images-amazon.com
PRICE_MONITOR_AMAZON_SSL_IMAGE_DOMAIN = 'https://images-eu.ssl-images-amazon.com'
Optional settings

The following settings can be adjusted but come with reasonable default values.

Product synchronization
# time after which products shall be refreshed
# Amazon only allows caching up to 24 hours, so the maximum value is 1440!
PRICE_MONITOR_AMAZON_PRODUCT_REFRESH_THRESHOLD_MINUTES = 720  # 12 hours
Notifications

To be able to send out the notification emails, set up a proper email backend (see Django documentation).

# time after which to notify the user again about a price limit hit (in minutes)
PRICE_MONITOR_SUBSCRIPTION_RENOTIFICATION_MINUTES = 10080  # 7 days

# sender address of the notification email
PRICE_MONITOR_EMAIL_SENDER = 'noreply@localhost'

# currency name to use on notifications
PRICE_MONITOR_DEFAULT_CURRENCY = 'EUR'

# subject and body of the notification emails
gettext = lambda x: x
PRICE_MONITOR_I18N_EMAIL_NOTIFICATION_SUBJECT = gettext(
    'Price limit for %(product)s reached'
)
PRICE_MONITOR_I18N_EMAIL_NOTIFICATION_BODY = gettext(
    'The price limit of %(price_limit)0.2f %(currency)s has been reached for the '
    'article "%(product_title)s" - the current price is %(price)0.2f %(currency)s.'
    '\n\nPlease support our platform by using this '
    'link for buying: %(link)s\n\n\nRegards,\nThe Team'
)

# name of the site in notifications
PRICE_MONITOR_SITENAME = 'Price Monitor'
Caching
# key of cache (according to project config) to use for graphs
# None disables caching.
PRICE_MONITOR_GRAPH_CACHE_NAME = None

# prefix for cache key used for graphs
PRICE_MONITOR_GRAPH_CACHE_KEY_PREFIX = 'graph_'

Celery settings

To be able to run the required Celery tasks, Celery itself has to be set up. Please see the Celery Documentation about how to setup the whole thing. You’ll need a broker and a result backend configured.

Management Commands

price_monitor_batch_create_products

A management command to batch create a number of products by providing their ASIN:

python manage.py price_monitor_batch_create_products <ASIN1> <ASIN2> <ASIN3>

price_monitor_recreate_product

Recreates a product with the given asin. If product already exists, it is deleted. Only use in development!

python manage.py price_monitor_recreate_product <ASIN>

Loggers

price_monitor

The app uses the logger “price_monitor” to log all error and info messages that are not included within a dedicated other logger. Please see the Django logging documentation for how to setup loggers.

price_monitor.product_advertising_api

Logger for everything related to the ProductAdvertisingAPI wrapper class that accesses the Amazon Product Advertising API through bottlenose.

price_monitor.utils

Logger for the utils module.

Tests

Coverage

codecov-graph

Internals

Model graph

Model Graph

Product advertising api synchronization

Task workflow

Image of Product advertising api synchronization workflow

Image of Product advertising api synchronization workflow

Change Log

0.3b2

Implemented enhancements:

  • Prepare for automatic releases #68

  • Increase performance of Amazon calls #41

  • Django 1.8 compatibility #32

  • Data reduction and clean up #27

  • Limit graphs #26

  • Show highest and lowest price ever #25

  • Implement a full-usable frontend #8

  • Add more tests #2

Fixed bugs:

  • Graphs empty for some products #65

  • Don’t show other peoples price limits #63

  • Graphs do not render correct values #60

  • ‘NoneType’ object has no attribute ‘url’ #59

  • Rename SynchronizeSingleProductTask #56

  • Sync on product creation not working #55

  • Clear old products and prices #47

  • Deleting a product subscription does not remove it from list view #42

  • Endless synchronization queue #38

  • Mark unavailable products #14

Closed issues:

  • Unpin beautifulsoup4==4.3.2 #50

Merged pull requests:

Pre-Releases

  • unfortunately everything before was not packaged and released nor tracked.

* This Change Log was automatically generated by github_changelog_generator and pandoc

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-amazon-price-monitor-0.3b2.tar.gz (206.6 kB view hashes)

Uploaded Source

Built Distribution

django_amazon_price_monitor-0.3b2-py2.py3-none-any.whl (235.5 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page