Skip to content

Commit

Permalink
Add vanilla interface (#100)
Browse files Browse the repository at this point in the history
* add genuine sync interface

* add style check to CI

* just codespell for now
  • Loading branch information
akaszynski authored Mar 28, 2021
1 parent 59a0a5c commit 6f20171
Show file tree
Hide file tree
Showing 9 changed files with 547 additions and 247 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# check spelling, codestyle
name: Style Check

on: [push, pull_request, workflow_dispatch]

jobs:
build:
runs-on: ubuntu-20.04

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Setup Python
uses: actions/[email protected]
with:
python-version: 3.8

- name: Style
run: |
pip install -r requirements_style.txt --disable-pip-version-check
make
26 changes: 1 addition & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,8 @@ CODESPELL_IGNORE ?= "ignore_words.txt"

all: doctest

doctest: codespell pydocstyle
doctest: codespell

codespell:
@echo "Running codespell"
@codespell $(CODESPELL_DIRS) -S $(CODESPELL_SKIP) -I $(CODESPELL_IGNORE)

pydocstyle:
@echo "Running pydocstyle"
@pydocstyle pyvista

doctest-modules:
@echo "Runnnig module doctesting"
pytest -v --doctest-modules pyvista

coverage:
@echo "Running coverage"
@pytest -v --cov pyvista

coverage-xml:
@echo "Reporting XML coverage"
@pytest -v --cov pyvista --cov-report xml

coverage-html:
@echo "Reporting HTML coverage"
@pytest -v --cov pyvista --cov-report html

mypy:
@echo "Running mypy static type checking"
mypy pyvista/core/ --no-incremental
54 changes: 42 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,43 @@ keepa
.. image:: https://codecov.io/gh/akaszynski/keepa/branch/master/graph/badge.svg
:target: https://codecov.io/gh/akaszynski/keepa

Python module to interface to `Keepa <https://keepa.com/>`_ to query for Amazon product information and history.
This Python module allows you to interface with the API at `Keepa
<https://keepa.com/>`_ to query for Amazon product information and
history. It also contains a plotting module to allow for plotting of
a product.

See API pricing at `Keepa API <https://keepa.com/#!api>`_

Documentation can be found on readthedocs at `keepa Documentation <https://keepaapi.readthedocs.io/en/latest/>`_.


Requirements
------------
Module is compatible with Python >= 3.5 . keepa requires:
Module is compatible with Python >= 3.5 and requires:

- ``numpy``
- ``aiohttp``
- ``matplotlib``
- ``tqdm``

Product history can be plotted from the raw data when ``matplotlib`` is installed.

Interfacing with the ``keepa`` requires an access key and a monthly subscription from `Keepa API <https://keepa.com/#!api>`_
Product history can be plotted from the raw data when ``matplotlib``
is installed.

Interfacing with the ``keepa`` requires an access key and a monthly
subscription from `Keepa API <https://keepa.com/#!api>`_

Installation
------------
Module can be installed from PyPi with:
Module can be installed from `PyPi <https://pypi.org/project/keepa/>`_ with:

.. code::
pip install keepa
Source code can also be downloaded from `GitHub <https://github.com/akaszynski/keepa>`_ and installed using ``python setup.py install`` or ``pip install .``
Source code can also be downloaded from `GitHub
<https://github.com/akaszynski/keepa>`_ and installed using:
``python setup.py install`` or ``pip install .``


Brief Example
Expand Down Expand Up @@ -70,9 +78,28 @@ Brief Example
Product Offers Plot


Detailed Example
----------------
Brief Example using async
-------------------------
Here's an example of obtaining a product and plotting its price and
offer history using the ``async`` interface:

.. code:: python
import keepa
# establish interface with keepa (this is not a real key)
mykey = '0000000000000000000000000000000000000000000000000000000000000000'
api = await keepa.AsyncKeepa.create(mykey)
# plot product request
request = 'B0088PUEPK'
products = await api.query(request)
product = products[0]
keepa.plot_product(product)
Detailed Examples
-----------------
Import interface and establish connection to server

.. code:: python
Expand Down Expand Up @@ -188,17 +215,20 @@ You can obtain the offers history for an ASIN (or multiple ASINs) using the ``of
plt.show()
If you plan to do a lot of simulatneous query, you might want to speedup query using
`wait=False` arguments.
``wait=False`` arguments.

.. code:: python
products = await api.query('059035342X', wait=False)
Credits
-------
This Python code, written by Alex Kaszynski, is based on Java code written by Marius Johann, CEO keepa. Java source is can be found at `api_backend <https://github.com/keepacom/api_backend/>`_.
This Python module, written by Alex Kaszynski and several
contribitors, is based on Java code written by Marius Johann, CEO
keepa. Java source is can be found at `api_backend <https://github.com/keepacom/api_backend/>`_.


License
-------
Apache License, please see license file. Work is credited to both Alex Kaszynski and Marius Johann.
Apache License, please see license file. Work is credited to both Alex
Kaszynski and Marius Johann.
5 changes: 2 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '1.0.0'
# The full version, including alpha/beta/rc tags.
release = '1.0.0'
# The short X.Y version.
release = version = '1.3.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
84 changes: 2 additions & 82 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
keepa Documentation
===================
This Python module allows you to interface with the API at `Keepa <https://keepa.com/>`_ to query for Amazon product information and history. It also contains a plotting module to allow for plotting of a product.

See API pricing at `Keepa API <https://keepa.com/#!api>`_
*******************

.. toctree::
:maxdepth: 2
Expand All @@ -11,85 +8,8 @@ See API pricing at `Keepa API <https://keepa.com/#!api>`_
product_query
api_methods

Brief Example
-------------
Here's an example of obtaining a product and plotting its price and offer history:

.. code:: python
import keepa
# establish interface with keepa (this is not a real key)
mykey = '0000000000000000000000000000000000000000000000000000000000000000'
api = keepa.Keepa(mykey)
# plot product request
request = 'B0088PUEPK'
products = api.query(request)
product = products[0]
keepa.plot_product(product)
.. figure:: ./images/Product_Price_Plot.png
:width: 500pt

Product Price Plot

.. figure:: ./images/Product_Offer_Plot.png
:width: 500pt

Product Offers Plot

Brief Example using async
-------------------------
Here's an example of obtaining a product and plotting its price and offer history:

.. code:: python
import keepa
# establish interface with keepa (this is not a real key)
mykey = '0000000000000000000000000000000000000000000000000000000000000000'
api = await keepa.AsyncKeepa.create(mykey)
# plot product request
request = 'B0088PUEPK'
products = await api.query(request)
product = products[0]
keepa.plot_product(product)
.. figure:: ./images/Product_Price_Plot.png
:width: 500pt

Product Price Plot

.. figure:: ./images/Product_Offer_Plot.png
:width: 500pt

Product Offers Plot

Installation
------------
``keepa`` can be installed from PyPi using

.. code::
pip install keepa --user
Source code can also be downloaded from `GitHub <https://github.com/akaszynski/keepa>`_ and installed using:

.. code::
python setup.py install
Acknowledgments
---------------
This Python code written by Alex Kaszynski is based on Java code written by Marius Johann, CEO keepa. Java source is can be found at `keepa <https://github.com/keepacom/api_backend/>`_.


License
-------
Apache License, please see license file. Work is credited to both Alex Kaszynski and Marius Johann.
.. include:: ../../README.rst


Indices and tables
Expand Down
42 changes: 31 additions & 11 deletions docs/source/product_query.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
Queries
=======
Interfacing with the ``keepa`` requires a valid access key. This requires a monthly subscription from `Pricing <https://keepa.com/#!api>`_. Here's a brief description of the subscription model from their website.
Interfacing with the ``keepa`` requires a valid access key. This
requires a monthly subscription from `Pricing
<https://keepa.com/#!api>`_. Here's a brief description of the
subscription model from their website.

All plans are prepaid for 1 month with a subscription model. A subscription can be canceled at any time. Multiple plans can be active on the same account and an upgrade is possible at any time, a downgrade once per month. The plans differentiate by the number of tokens generated per minute. For example: With a single token you can retrieve the complete data set for one product. Unused tokens expire after one hour. You can find more information on how our plans work in our documentation.
All plans are prepaid for 1 month with a subscription model. A
subscription can be canceled at any time. Multiple plans can be active
on the same account and an upgrade is possible at any time, a
downgrade once per month. The plans differentiate by the number of
tokens generated per minute. For example: With a single token you can
retrieve the complete data set for one product. Unused tokens expire
after one hour. You can find more information on how our plans work in
our documentation.


Connecting to KeepaAPI
~~~~~~~~~~~~~~~~~~~~~~
Import interface and establish connection to server
Import interface and establish connection to server:

.. code:: python
Expand Down Expand Up @@ -55,7 +65,7 @@ The ``products`` variable is a list of product data with one entry per successfu
print('ASIN is ' + products[0]['asin'])
print('Title is ' + products[0]['title'])
When the parameter ``history`` is True (enabled by default, the each
When the parameter ``history`` is ``True`` (enabled by default), each
product contains a The raw data is contained within each product
result. Raw data is stored as a dictionary with each key paired with
its associated time history.
Expand Down Expand Up @@ -85,9 +95,13 @@ its associated time history.
2014-08-10 18:00:00 $57.00
2014-08-10 20:00:00 $52.51
Each time a user makes a query to keepa as well as other points in time, an entry is stored on their servers. This means that there will sometimes be gaps in the history followed by closely spaced entries like in this example data.
Each time a user makes a query to keepa as well as other points in
time, an entry is stored on their servers. This means that there will
sometimes be gaps in the history followed by closely spaced entries
like in this example data.

The data dictionary contains keys for each type of history available for the product. These keys include:
The data dictionary contains keys for each type of history available
for the product. These keys include:

AMAZON
Amazon price history
Expand Down Expand Up @@ -174,7 +188,8 @@ The data dictionary contains keys for each type of history available for the pro
The trade in price history. Amazon trade-in is not available for every locale.


Each data key has a corresponding ``_time`` key containing the time values of each key. These can be plotted with:
Each data key has a corresponding ``_time`` key containing the time
values of each key. These can be plotted with:

.. code:: python
Expand All @@ -183,9 +198,11 @@ Each data key has a corresponding ``_time`` key containing the time values of ea
history = product['data']
plt.step(history[key], history[key + '_time'], where='pre')
Historical data should be plotted as a step plot since the data is discontinuous. Values are unknown between each entry.
Historical data should be plotted as a step plot since the data is
discontinuous. Values are unknown between each entry.

The product history can also be plotted from the module if ``matplotlib`` is installed
The product history can also be plotted from the module if
``matplotlib`` is installed

.. code:: python
Expand Down Expand Up @@ -229,7 +246,8 @@ You can obtain the offers history for an ASIN (or multiple ASINs) using the ``of
2018-02-03 08:32:00 $203.48
2018-02-04 08:40:00 $217.37
Not all offers are active and some are only historical. The following example plots the historyof active offers for a single amazon product.
Not all offers are active and some are only historical. The following
example plots the historyof active offers for a single Amazon product.

.. code:: python
Expand Down Expand Up @@ -262,7 +280,9 @@ Not all offers are active and some are only historical. The following example pl

Category Queries
~~~~~~~~~~~~~~~~
You can retrieve an ASIN list of the most popular products based on sales in a specific category or product group. Here's an example that assumes you've already setup your api.
You can retrieve an ASIN list of the most popular products based on
sales in a specific category or product group. Here's an example that
assumes you've already setup your api.

.. code:: python
Expand Down
Loading

1 comment on commit 6f20171

@dehidehidehi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I am wrong, but I don't seem to have spotted an implementation which enforces that tests.py are run over the regular interface AND THEN the async interface.
This could help to prevent forgetting about implementing new commits on both interfaces.

Please sign in to comment.