Skip to content

Commit

Permalink
Merge branch 'main' into release/1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
akaszynski committed Apr 2, 2024
2 parents e048f98 + 27b1cab commit eca4a88
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 101 deletions.
6 changes: 0 additions & 6 deletions .github/dependabot.yml

This file was deleted.

13 changes: 5 additions & 8 deletions .github/workflows/testing-and-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
**/setup.py
**/requirements*.txt

- name: Install
run: |
Expand All @@ -46,7 +43,7 @@ jobs:
run: |
pytest -v --cov keepa --cov-report xml
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
if: matrix.python-version == '3.12'
name: 'Upload coverage to codecov'

Expand All @@ -58,7 +55,7 @@ jobs:
- name: Upload wheel
if: matrix.python-version == '3.12'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: keepa-wheel
path: dist/
Expand All @@ -75,7 +72,7 @@ jobs:
permissions:
id-token: write # this permission is mandatory for trusted publishing
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
path: dist/
- name: Flatten directory structure
Expand All @@ -87,7 +84,7 @@ jobs:
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
files: |
Expand Down
11 changes: 3 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@
# See https://pre-commit.ci/
ci:
autofix_prs: true
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/keewis/blackdoc
rev: v0.3.8
rev: v0.3.9
hooks:
- id: blackdoc
files: '\.py$'
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
rev: v0.3.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -32,7 +27,7 @@ repos:
additional_dependencies: [toml]
exclude: "tests/"
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
rev: v3.15.2
hooks:
- id: pyupgrade
args: [--py38-plus, --keep-runtime-typing]
Expand Down
1 change: 0 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ Unit testing will automatically enforce minimum code coverage standards.

Next, to ensure your code meets minimum code styling standards, run::

pip install pre-commit
pre-commit run --all-files

Finally, `create a pull request`_ from your fork and I'll be sure to review it.
Expand Down
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Sphinx configuration file for keepaapi."""

# import pydata_sphinx_theme # noqa
from datetime import datetime

Expand Down
12 changes: 3 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ dependencies = [
"numpy >=1.9.3",
"requests >=2.2",
"tqdm",
"aiohttp; python_version!='3.12.*'",
"aiohttp==3.9.0b0; python_version=='3.12.*'", # until aiohttp gets upgraded
"pandas",
"aiohttp",
"pandas <= 3.0",
]

[project.urls]
Expand Down Expand Up @@ -61,10 +60,5 @@ combine_as_imports = true

[tool.ruff]
line-length = 100

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F"]
select = ["E", "F", "W", "I001"] # pyflakes, pycodestyle, isort
ignore = []
42 changes: 0 additions & 42 deletions setup.py

This file was deleted.

59 changes: 37 additions & 22 deletions src/keepa/interface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Interface module to download Amazon product and history data from keepa.com."""

import asyncio
import datetime
import json
Expand Down Expand Up @@ -43,8 +44,8 @@ def wrapper(target):

# domain codes
# Valid values: [ 1: com | 2: co.uk | 3: de | 4: fr | 5:
# co.jp | 6: ca | 7: cn | 8: it | 9: es | 10: in | 11: com.mx ]
DCODES = ["RESERVED", "US", "GB", "DE", "FR", "JP", "CA", "CN", "IT", "ES", "IN", "MX"]
# co.jp | 6: ca | 7: cn | 8: it | 9: es | 10: in | 11: com.mx | 12: com.br ]
DCODES = ["RESERVED", "US", "GB", "DE", "FR", "JP", "CA", "CN", "IT", "ES", "IN", "MX", "BR"]

# csv indices. used when parsing csv and stats fields.
# https://github.com/keepacom/api_backend
Expand Down Expand Up @@ -505,9 +506,9 @@ def query(
timestamps (unix epoch time milliseconds) or two date
strings (ISO8601, with or without time in UTC).
domain : str, optional
domain : str, default: "US"
One of the following Amazon domains: RESERVED, US, GB, DE,
FR, JP, CA, CN, IT, ES, IN, MX Defaults to US.
FR, JP, CA, CN, IT, ES, IN, MX, BR.
offers : int, optional
Adds available offers to product data. Default 0. Must be between
Expand Down Expand Up @@ -885,7 +886,7 @@ def _product_query(self, items, product_code_is_asin=True, **kwargs):
domain : str
One of the following Amazon domains:
RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX
RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX, BR.
offers : bool, optional
Adds product offers to product data.
Expand Down Expand Up @@ -1021,10 +1022,9 @@ def best_sellers_query(self, category, rank_avg_range=0, domain="US", wait=True)
the best sellers list for. You can find category node ids
via the category search "search_for_categories".
domain : str
Amazon locale you want to access. Must be one of the following
RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX
Default US.
domain : str, default: "US"
Amazon locale you want to access. Must be one of the following:
RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX, BR.
wait : bool, optional
Wait available token before doing effective query.
Expand Down Expand Up @@ -1077,7 +1077,10 @@ def best_sellers_query(self, category, rank_avg_range=0, domain="US", wait=True)
...
"""
assert domain in DCODES, "Invalid domain code"
if domain not in DCODES:
raise ValueError(
f"Invalid domain code {domain}. Should be one of the following:\n{DCODES}"
)

payload = {
"key": self.accesskey,
Expand All @@ -1100,10 +1103,9 @@ def search_for_categories(self, searchterm, domain="US", wait=True) -> list:
searchterm : str
Input search term.
domain : str, default: 'US'
Amazon locale you want to access. Must be one of the following
RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX
Default US.
domain : str, default: "US"
Amazon locale you want to access. Must be one of the following:
RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX, BR.
wait : bool, default: True
Wait available token before doing effective query.
Expand Down Expand Up @@ -1136,7 +1138,10 @@ def search_for_categories(self, searchterm, domain="US", wait=True) -> list:
144 Science Fiction & Fantasy
"""
assert domain in DCODES, "Invalid domain code"
if domain not in DCODES:
raise ValueError(
f"Invalid domain code {domain}. Should be one of the following:\n{DCODES}"
)

payload = {
"key": self.accesskey,
Expand All @@ -1162,9 +1167,8 @@ def category_lookup(self, category_id, domain="US", include_parents=False, wait=
categories.
domain : str, default: "US"
Amazon locale you want to access. Must be one of the following
RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX
Default US
Amazon locale you want to access. Must be one of the following:
RESERVED, US, GB, DE, FR, JP, CA, CN, IT, ES, IN, MX, BR.
include_parents : bool, default: False
Include parents.
Expand Down Expand Up @@ -1211,7 +1215,9 @@ def category_lookup(self, category_id, domain="US", include_parents=False, wait=
"""
if domain not in DCODES:
raise ValueError("Invalid domain code")
raise ValueError(
f"Invalid domain code {domain}. Should be one of the following:\n{DCODES}"
)

payload = {
"key": self.accesskey,
Expand Down Expand Up @@ -2884,7 +2890,10 @@ async def _product_query(self, items, product_code_is_asin=True, **kwargs):
@is_documented_by(Keepa.best_sellers_query)
async def best_sellers_query(self, category, rank_avg_range=0, domain="US", wait=True):
"""Documented by Keepa.best_sellers_query."""
assert domain in DCODES, "Invalid domain code"
if domain not in DCODES:
raise ValueError(
f"Invalid domain code {domain}. Should be one of the following:\n{DCODES}"
)

payload = {
"key": self.accesskey,
Expand All @@ -2902,7 +2911,10 @@ async def best_sellers_query(self, category, rank_avg_range=0, domain="US", wait
@is_documented_by(Keepa.search_for_categories)
async def search_for_categories(self, searchterm, domain="US", wait=True):
"""Documented by Keepa.search_for_categories."""
assert domain in DCODES, "Invalid domain code"
if domain not in DCODES:
raise ValueError(
f"Invalid domain code {domain}. Should be one of the following:\n{DCODES}"
)

payload = {
"key": self.accesskey,
Expand All @@ -2922,7 +2934,10 @@ async def search_for_categories(self, searchterm, domain="US", wait=True):
@is_documented_by(Keepa.category_lookup)
async def category_lookup(self, category_id, domain="US", include_parents=0, wait=True):
"""Documented by Keepa.category_lookup."""
assert domain in DCODES, "Invalid domain code"
if domain not in DCODES:
raise ValueError(
f"Invalid domain code {domain}. Should be one of the following:\n{DCODES}"
)

payload = {
"key": self.accesskey,
Expand Down
1 change: 1 addition & 0 deletions src/keepa/plotting.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Plotting module product data returned from keepa interface module."""

import numpy as np

from keepa.interface import keepa_minutes_to_time, parse_csv
Expand Down
5 changes: 3 additions & 2 deletions tests/test_async_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,16 @@ async def test_invalid_category(api):
async def test_stock(api):
request = await api.query(PRODUCT_ASIN, history=False, stock=True, offers=20)

# all live offers must have stock
# all live offers should have stock
product = request[0]
assert product["offersSuccessful"]
live = product["liveOffersOrder"]
if live is not None:
for offer in product["offers"]:
if offer["offerId"] in live:
if "stockCSV" in offer:
assert offer["stockCSV"][-1]
if not offer["stockCSV"][-1]:
warnings.warn(f"No live offers for {PRODUCT_ASIN}")
else:
warnings.warn(f"No live offers for {PRODUCT_ASIN}")

Expand Down
8 changes: 5 additions & 3 deletions tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,10 @@ def test_productquery_offers_multiple(api):


def test_domain(api):
request = api.query(PRODUCT_ASIN, history=False, domain="DE")
asin = "0394800028"
request = api.query(asin, history=False, domain="BR")
product = request[0]
assert product["asin"] == PRODUCT_ASIN
assert product["asin"] == asin


def test_invalid_domain(api):
Expand Down Expand Up @@ -364,7 +365,8 @@ def test_stock(api):
for offer in product["offers"]:
if offer["offerId"] in live:
if "stockCSV" in offer:
assert offer["stockCSV"][-1]
if not offer["stockCSV"][-1]:
warnings.warn(f"No live offers for {PRODUCT_ASIN}")
else:
warnings.warn(f"No live offers for {PRODUCT_ASIN}")

Expand Down

0 comments on commit eca4a88

Please sign in to comment.