Metadata-Version: 2.0
Name: capybara
Version: 0.1.0
Summary: A simple wrapper for multiple tokens of multiple APIs
Home-page: https://github.com/AkihikoITOH/capybara
Author: ITOH Akihiko
Author-email: akihiko.mus+pypi@gmail.com
License: MIT
Keywords: amazon,product advertising,rakuten,item search,api
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries
Classifier: Topic :: Utilities
Classifier: License :: OSI Approved :: MIT License
Requires-Dist: python-amazon-simple-product-api
Requires-Dist: requests

Capybara: A simple wrapper for multiple tokens of multiple APIs
===============================================================

About
-----

APIs usually require access tokens to limit frequencies of requests.

If you want to request over limitations, you need to generate multiple
tokens and roop over them.

Capybara is a simple wrapper for multiple tokens.

Dependencies
------------

-  Installed
   `python-amazon-simple-product-api <https://github.com/yoavaviram/python-amazon-simple-product-api>`__
   (``pip install python-amazon-simple-product-api``)
-  Installed `requests <http://docs.python-requests.org/en/latest/>`__
   (``pip install requests``)
-  Valid API tokens for each service you want to use

Installation
------------

::

    pip install capybara

or

::

    pip install git+https@github.com:AkihikoITOH/capybara.git

Available Services
------------------

Send Pull Requests to add services!

Amazon
~~~~~~

Wrapper of `Amazon Product Advertising
API <https://affiliate.amazon.co.jp/gp/advertising/api/detail/main.html>`__.

楽天
~~~~

Wrapper of
`楽天商品検索API <https://webservice.rakuten.co.jp/api/ichibaitemsearch/>`__.

Usage
-----

As a Python module (**Recommended**)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

    import capybara

    c = Capybara(config_dir='/path/to/config/', tokens_dir='/path/to/tokens/')

    # Amazon
    result = c.get(service='amazon', item='B005CSYH5Y')
    print result.title
    print result.get_attribute('ProductGroup')
    print result.get_attribute('Manufacturer')
    print result.get_attributes(['ProductGroup', 'Manufacturer'])

    # 楽天
    result = c.get(service='rakuten', item='urutoragion:10000866')
    print result['Items'][0]['Item']['itemName']
    print result['Items'][0]['Item']['genreId']
    print result['Items'][0]['Item']['shopName']

As a command line tool (Deprecated)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: shell

    $ python capybaracli.py -h

    > usage: capybaracli.py [-h] {amazon,rakuten} item
    >
    > Capybara: Wrapper for multiple tokens of multiple APIs
    >
    > positional arguments:
    >   {amazon,rakuten}  Service name
    >   item              Item id
    >
    > optional arguments:
    >   -h, --help        show this help message and exit

Setup
-----

::

    anywhere/you/like
       ├── config
       │   ├── amazon_config.json
       │   └── rakuten_config.json
       └── tokens
           ├── amazon_tokens.tsv
           └── rakuten_tokens.tsv

    capybara
      ├── abst_wrapper.py
      ├── amazon_wrapper.py
      ├── capybara.py
      ├── capybaracli.py
      └── rakuten_wrapper.py

config directory
~~~~~~~~~~~~~~~~

Set **access frequency** or other configurations in **JSON** format for
each service.

+-------------+-----------+--------------------------------------------------------------+-----------+
| attribute   | type      | description                                                  | example   |
+=============+===========+==============================================================+===========+
| interval    | integer   | interval time between requests per token (in milli second)   | 1000      |
+-------------+-----------+--------------------------------------------------------------+-----------+
| slow        | float     | extension ratio of interval                                  | 1.2       |
+-------------+-----------+--------------------------------------------------------------+-----------+

``path/to/config/sample_config.json``

.. code:: javascript

    {
        "interval": 1000,
        "slow": 1.2
    }

**Note: Attributes must be in lower cases and "double quoted".**

Note
^^^^

-  Actual interval time per token will be ``[interval]*[slow]``
-  Thus actual access frequency(per hour) will be
   ``[# of tokens]*3600/[interval]*[slow]``

tokens directory
~~~~~~~~~~~~~~~~

List **access tokens** and other required parameters in **TSV** format
for each service.

See `Product Advertising
API <https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html>`__
to get new access tokens.

Amazon
^^^^^^

+---------------+-----------------+
| parameter     | description     |
+===============+=================+
| ACCESS\_KEY   | access key      |
+---------------+-----------------+
| SECRET\_KEY   | secret key      |
+---------------+-----------------+
| ASSOC\_TAG    | associate tag   |
+---------------+-----------------+
| LOCALE        | locale          |
+---------------+-----------------+

``path/to/tokens/amazon_tokens.tsv``

::

    ACCESS_KEY1 SECRET_KEY1 ASSOC_TAG1  LOCALE
    ACCESS_KEY2 SECRET_KEY2 ASSOC_TAG2  LOCALE
    ACCESS_KEY3 SECRET_KEY3 ASSOC_TAG3  LOCALE
    ACCESS_KEY4 SECRET_KEY4 ASSOC_TAG4  LOCALE

楽天
^^^^

See
`楽天商品検索API <https://webservice.rakuten.co.jp/api/ichibaitemsearch/>`__
to get new access tokens.

+-----------------+------------------+
| parameter       | description      |
+=================+==================+
| applicationId   | application id   |
+-----------------+------------------+

``lib/tokens/rakuten_tokens.tsv``

::

    applicationId1
    applicationId2
    applicationId3
    applicationId4

License
-------

Copyright © 2015 ITOH Akihiko

See LICENSE for details.


