Skip to content

Commit

Permalink
add back in a few missing imports; use ruff (#155)
Browse files Browse the repository at this point in the history
* add back in a few missing imports; use ruff

* quarterly update pre-commit

* use latest download artifact

* move target for live data back to 60 days
  • Loading branch information
akaszynski authored Nov 2, 2023
1 parent a2552ac commit 32cf883
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 78 deletions.
4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/testing-and-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
permissions:
id-token: write # this permission is mandatory for trusted publishing
steps:
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v3
with:
path: dist/
- name: Flatten directory structure
Expand Down
17 changes: 8 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
# See https://pre-commit.ci/
ci:
autofix_prs: true
autoupdate_schedule: monthly
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black
- repo: https://github.com/keewis/blackdoc
rev: v0.3.8
hooks:
Expand All @@ -17,10 +13,13 @@ repos:
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
hooks:
- id: flake8
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
exclude: ^(docs/|tests)
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
Expand All @@ -33,7 +32,7 @@ repos:
additional_dependencies: [toml]
exclude: "tests/"
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py38-plus, --keep-runtime-typing]
Expand Down
2 changes: 0 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Sphinx configuration file for keepaapi."""
# import pydata_sphinx_theme # noqa
from datetime import datetime
from io import open as io_open
import os

from keepa import __version__

Expand Down
12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ force_sort_within_sections = true
# Combines "as" imports on the same line
combine_as_imports = true

[tool.black]
[tool.ruff]
line-length = 100
skip-string-normalization = true
target-version = ['py39']
exclude='\.eggs|\.git|\.mypy_cache|\.tox|\.venv|_build|buck-out|build|dist|node_modules'

[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"]
ignore = []
5 changes: 0 additions & 5 deletions requirements_test.txt

This file was deleted.

5 changes: 5 additions & 0 deletions src/keepa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

__version__ = "1.4.dev0"
from keepa.interface import ( # noqa: F401
DCODES,
KEEPA_ST_ORDINAL,
SCODES,
AsyncKeepa,
Keepa,
convert_offer_history,
csv_indices,
format_items,
keepa_minutes_to_time,
parse_csv,
process_used_buybox,
run_and_get,
)
Expand Down
98 changes: 49 additions & 49 deletions src/keepa/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,28 +364,28 @@ class Keepa:
Create the api object.
>>> import keepa
>>> key = '<REAL_KEEPA_KEY>'
>>> key = "<REAL_KEEPA_KEY>"
>>> api = keepa.Keepa(key)
Request data from two ASINs.
>>> products = api.query(['0439064872', '1426208081'])
>>> products = api.query(["0439064872", "1426208081"])
Print item details.
>>> print('Item 1')
>>> print('\t ASIN: {:s}'.format(products[0]['asin']))
>>> print('\t Title: {:s}'.format(products[0]['title']))
>>> print("Item 1")
>>> print("\t ASIN: {:s}".format(products[0]["asin"]))
>>> print("\t Title: {:s}".format(products[0]["title"]))
Item 1
ASIN: 0439064872
Title: Harry Potter and the Chamber of Secrets (2)
Print item price.
>>> usedprice = products[0]['data']['USED']
>>> usedtimes = products[0]['data']['USED_time']
>>> print('\t Used price: ${:.2f}'.format(usedprice[-1]))
>>> print('\t as of: {:s}'.format(str(usedtimes[-1])))
>>> usedprice = products[0]["data"]["USED"]
>>> usedtimes = products[0]["data"]["USED_time"]
>>> print("\t Used price: ${:.2f}".format(usedprice[-1]))
>>> print("\t as of: {:s}".format(str(usedtimes[-1])))
Used price: $0.52
as of: 2023-01-03 04:46:00
Expand Down Expand Up @@ -418,7 +418,7 @@ def time_to_refill(self) -> float:
should be 0.0 seconds.
>>> import keepa
>>> key = '<REAL_KEEPA_KEY>'
>>> key = "<REAL_KEEPA_KEY>"
>>> api = keepa.Keepa(key)
>>> api.time_to_refill
0.0
Expand Down Expand Up @@ -738,10 +738,10 @@ def query(
keepa interface.
>>> import keepa
>>> key = '<REAL_KEEPA_KEY>'
>>> key = "<REAL_KEEPA_KEY>"
>>> api = keepa.Keepa(key)
>>> response = api.query('B0088PUEPK')
>>> response[0]['title']
>>> response = api.query("B0088PUEPK")
>>> response[0]["title"]
'Western Digital 1TB WD Blue PC Internal Hard Drive HDD - 7200 RPM,
SATA 6 Gb/s, 64 MB Cache, 3.5" - WD10EZEX'
Expand All @@ -751,24 +751,24 @@ def query(
>>> import asyncio
>>> import keepa
>>> async def main():
... key = '<REAL_KEEPA_KEY>'
... key = "<REAL_KEEPA_KEY>"
... api = await keepa.AsyncKeepa().create(key)
... return await api.query('B0088PUEPK')
... return await api.query("B0088PUEPK")
...
>>> response = asyncio.run(main())
>>> response[0]['title']
>>> response[0]["title"]
'Western Digital 1TB WD Blue PC Internal Hard Drive HDD - 7200 RPM,
SATA 6 Gb/s, 64 MB Cache, 3.5" - WD10EZEX'
Load in product offers and convert the buy box data into a
``pandas.DataFrame``.
>>> import keepa
>>> key = '<REAL_KEEPA_KEY>'
>>> key = "<REAL_KEEPA_KEY>"
>>> api = keepa.Keepa(key)
>>> response = api.query('B0088PUEPK', offers=20)
>>> response = api.query("B0088PUEPK", offers=20)
>>> product = response[0]
>>> buybox_info = product['buyBoxUsedHistory']
>>> buybox_info = product["buyBoxUsedHistory"]
>>> df = keepa.process_used_buybox(buybox_info)
datetime user_id condition isFBA
0 2022-11-02 16:46:00 A1QUAC68EAM09F Used - Like New True
Expand Down Expand Up @@ -1040,7 +1040,7 @@ def best_sellers_query(self, category, rank_avg_range=0, domain="US", wait=True)
Query for the best sellers among the ``"movies"`` category.
>>> import keepa
>>> key = '<REAL_KEEPA_KEY>'
>>> key = "<REAL_KEEPA_KEY>"
>>> api = keepa.Keepa(key)
>>> categories = api.search_for_categories("movies")
>>> category = list(categories.items())[0][0]
Expand All @@ -1060,7 +1060,7 @@ def best_sellers_query(self, category, rank_avg_range=0, domain="US", wait=True)
>>> import asyncio
>>> import keepa
>>> async def main():
... key = '<REAL_KEEPA_KEY>'
... key = "<REAL_KEEPA_KEY>"
... api = await keepa.AsyncKeepa().create(key)
... categories = await api.search_for_categories("movies")
... category = list(categories.items())[0][0]
Expand Down Expand Up @@ -1120,11 +1120,11 @@ def search_for_categories(self, searchterm, domain="US", wait=True) -> list:
Print all categories from science.
>>> import keepa
>>> key = '<REAL_KEEPA_KEY>'
>>> key = "<REAL_KEEPA_KEY>"
>>> api = keepa.Keepa(key)
>>> categories = api.search_for_categories('science')
>>> categories = api.search_for_categories("science")
>>> for cat_id in categories:
... print(cat_id, categories[cat_id]['name'])
... print(cat_id, categories[cat_id]["name"])
...
9091159011 Behavioral Sciences
8407535011 Fantasy, Horror & Science Fiction
Expand Down Expand Up @@ -1182,7 +1182,7 @@ def category_lookup(self, category_id, domain="US", include_parents=False, wait=
Use 0 to return all root categories.
>>> import keepa
>>> key = '<REAL_KEEPA_KEY>'
>>> key = "<REAL_KEEPA_KEY>"
>>> api = keepa.Keepa(key)
>>> categories = api.category_lookup(0)
Expand Down Expand Up @@ -1300,10 +1300,10 @@ def seller_query(
Return the information from seller ``'A2L77EE7U53NWQ'``.
>>> import keepa
>>> key = '<REAL_KEEPA_KEY>'
>>> key = "<REAL_KEEPA_KEY>"
>>> api = keepa.Keepa(key)
>>> seller_info = api.seller_query('A2L77EE7U53NWQ', 'US')
>>> seller_info['A2L77EE7U53NWQ']['sellerName']
>>> seller_info = api.seller_query("A2L77EE7U53NWQ", "US")
>>> seller_info["A2L77EE7U53NWQ"]["sellerName"]
'Amazon Warehouse'
Notes
Expand Down Expand Up @@ -2376,10 +2376,10 @@ def product_finder(self, product_parms, domain="US", wait=True, n_products=50) -
``keepa.Keepa`` class. Sort by current sales.
>>> import keepa
>>> api = keepa.Keepa('<ENTER_ACTUAL_KEY_HERE>')
>>> api = keepa.Keepa("<ENTER_ACTUAL_KEY_HERE>")
>>> product_parms = {
... 'author': 'jim butcher',
... 'sort': ["current_SALES", "asc"],
... "author": "jim butcher",
... "sort": ["current_SALES", "asc"],
... }
>>> asins = api.product_finder(product_parms, n_products=100)
>>> asins
Expand All @@ -2396,9 +2396,9 @@ def product_finder(self, product_parms, domain="US", wait=True, n_products=50) -
>>> import asyncio
>>> import keepa
>>> product_parms = {'author': 'jim butcher'}
>>> product_parms = {"author": "jim butcher"}
>>> async def main():
... key = '<REAL_KEEPA_KEY>'
... key = "<REAL_KEEPA_KEY>"
... api = await keepa.AsyncKeepa().create(key)
... return await api.product_finder(product_parms)
...
Expand All @@ -2425,7 +2425,7 @@ def product_finder(self, product_parms, domain="US", wait=True, n_products=50) -
payload = {
"key": self.accesskey,
"domain": DCODES.index(domain),
"selection": json.dumps({**product_parms, **{'perPage': n_products}}),
"selection": json.dumps({**product_parms, **{"perPage": n_products}}),
}

response = self._request("query", payload, wait=wait)
Expand Down Expand Up @@ -2496,7 +2496,7 @@ def deals(self, deal_parms, domain="US", wait=True) -> dict:
``keepa.Keepa`` class
>>> import keepa
>>> key = '<REAL_KEEPA_KEY>'
>>> key = "<REAL_KEEPA_KEY>"
>>> api = keepa.Keepa(key)
>>> deal_parms = {
... "page": 0,
Expand All @@ -2508,7 +2508,7 @@ def deals(self, deal_parms, domain="US", wait=True) -> dict:
Get the title of the first deal.
>>> deals['dr'][0]['title']
>>> deals["dr"][0]["title"]
'Orange Cream Rooibos, Tea Bags - Vanilla, Orange | Caffeine-Free,
Antioxidant-rich, Hot & Iced | The Spice Hut, First Sip Of Tea'
Expand All @@ -2524,7 +2524,7 @@ def deals(self, deal_parms, domain="US", wait=True) -> dict:
... "includeCategories": [16310101],
... }
>>> async def main():
... key = '<REAL_KEEPA_KEY>'
... key = "<REAL_KEEPA_KEY>"
... api = await keepa.AsyncKeepa().create(key)
... categories = await api.search_for_categories("movies")
... return await api.deals(deal_parms)
Expand Down Expand Up @@ -2630,9 +2630,9 @@ class AsyncKeepa:
>>> import asyncio
>>> import keepa
>>> product_parms = {'author': 'jim butcher'}
>>> product_parms = {"author": "jim butcher"}
>>> async def main():
... key = '<REAL_KEEPA_KEY>'
... key = "<REAL_KEEPA_KEY>"
... api = await keepa.AsyncKeepa().create(key)
... return await api.product_finder(product_parms)
...
Expand All @@ -2652,12 +2652,12 @@ class AsyncKeepa:
>>> import asyncio
>>> import keepa
>>> async def main():
... key = '<REAL_KEEPA_KEY>'
... key = "<REAL_KEEPA_KEY>"
... api = await keepa.AsyncKeepa().create(key)
... return await api.query('B0088PUEPK')
... return await api.query("B0088PUEPK")
...
>>> response = asyncio.run(main())
>>> response[0]['title']
>>> response[0]["title"]
'Western Digital 1TB WD Blue PC Internal Hard Drive HDD - 7200 RPM,
SATA 6 Gb/s, 64 MB Cache, 3.5" - WD10EZEX'
Expand Down Expand Up @@ -3115,11 +3115,11 @@ def process_used_buybox(buybox_info: List[str]) -> pd.DataFrame:
``pandas.DataFrame``.
>>> import keepa
>>> key = '<REAL_KEEPA_KEY>'
>>> key = "<REAL_KEEPA_KEY>"
>>> api = keepa.Keepa(key)
>>> response = api.query('B0088PUEPK', offers=20)
>>> response = api.query("B0088PUEPK", offers=20)
>>> product = response[0]
>>> buybox_info = product['buyBoxUsedHistory']
>>> buybox_info = product["buyBoxUsedHistory"]
>>> df = keepa.process_used_buybox(buybox_info)
datetime user_id condition isFBA
0 2022-11-02 16:46:00 A1QUAC68EAM09F Used - Like New True
Expand Down Expand Up @@ -3156,10 +3156,10 @@ def process_used_buybox(buybox_info: List[str]) -> pd.DataFrame:

df = pd.DataFrame(
{
'datetime': datetime_arr,
'user_id': user_id_arr,
'condition': condition_arr,
'isFBA': isFBA_arr,
"datetime": datetime_arr,
"user_id": user_id_arr,
"condition": condition_arr,
"isFBA": isFBA_arr,
}
)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_async_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ async def test_productquery_update(api):
# should be live data
now = datetime.datetime.now()
delta = now - product["data"]["USED_time"][-1]
assert delta.days <= 35
assert delta.days <= 60

# check for empty arrays
history = product["data"]
Expand Down Expand Up @@ -262,7 +262,7 @@ async def test_bestsellers(api):
@pytest.mark.asyncio
async def test_buybox_used(api):
request = await api.query(HARD_DRIVE_PRODUCT_ASIN, history=False, offers=20)
df = keepa.process_used_buybox(request[0]['buyBoxUsedHistory'])
df = keepa.process_used_buybox(request[0]["buyBoxUsedHistory"])
assert isinstance(df, pd.DataFrame)


Expand Down
Loading

0 comments on commit 32cf883

Please sign in to comment.