Skip to content

Commit 8e13fbc

Browse files
committed
chore: update ruff version and formatting
1 parent 0f8e9d1 commit 8e13fbc

File tree

10 files changed

+1497
-93
lines changed

10 files changed

+1497
-93
lines changed

pyproject.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[build-system]
2-
requires = ["hatchling"]
3-
build-backend = "hatchling.build"
4-
51
[project]
62
name = "WIOpy"
73
version = "1.1.0"
@@ -50,9 +46,12 @@ line-length = 100
5046
fix = true
5147
target-version = "py38"
5248

53-
unfixable = ["F841"]
54-
ignore = ["PLR0913", "ISC001", "PLR2004"]
55-
5649
[tool.ruff.lint]
5750
select = ["E", "F", "B", "W", "Q", "A", "I", "D",
5851
"UP", "ASYNC", "FA", "ISC", "RET", "SIM", "ARG", "PL", "RUF"]
52+
ignore = ["PLR0913", "ISC001", "PLR2004", "D203", "D212"]
53+
unfixable = ["F841"]
54+
55+
[build-system]
56+
requires = ["hatchling"]
57+
build-backend = "hatchling.build"

uv.lock

Lines changed: 1309 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wiopy/AsyncWIO.py

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
"""Walmart IO Async API.
1+
"""
2+
Walmart IO Async API.
23
34
Please read the Walmart Docs for up to date list of endpoints and parameters
45
"""
6+
57
from __future__ import annotations
68

79
import base64
@@ -33,7 +35,8 @@
3335

3436

3537
class AsyncWalmartIO:
36-
"""The main Walmart IO API interface.
38+
"""
39+
The main Walmart IO API interface.
3740
3841
Optional:
3942
-------
@@ -48,16 +51,17 @@ class AsyncWalmartIO:
4851
... private_key_filename='./WM_IO_private_key.pem',
4952
... consumer_id='XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
5053
... )
54+
5155
"""
5256

5357
__slots__ = (
54-
"_private_key_version",
55-
"_private_key",
5658
"_consumer_id",
57-
"headers",
59+
"_private_key",
60+
"_private_key_version",
5861
"_update_daily_calls_time",
5962
"daily_calls",
6063
"daily_calls_remaining",
64+
"headers",
6165
"publisherId",
6266
)
6367

@@ -72,7 +76,8 @@ def __init__(
7276
daily_calls: int = 5000,
7377
publisherId: str | None = None,
7478
) -> None:
75-
"""WalmartIO API Connection.
79+
"""
80+
WalmartIO API Connection.
7681
7782
Parameters
7883
----------
@@ -95,6 +100,7 @@ def __init__(
95100
-----
96101
To Generate the public and private key (https://walmart.io/key-tutorial).
97102
The filename will look something like `./WM_IO_private_key.pem`
103+
98104
"""
99105
self._private_key_version = private_key_version
100106

@@ -117,7 +123,8 @@ def __init__(
117123
log.info(f"Walmart IO connection with consumer id ending in {consumer_id[-6:]}")
118124

119125
async def catalog_product(self, **kwargs) -> WalmartCatalog:
120-
"""Catalog Product Endpoint.
126+
"""
127+
Catalog Product Endpoint.
121128
122129
Allows a developer to retrieve the products catalog in a paginated fashion.
123130
Catalog can be filtered by category, brand and/or any special offers like rollback,
@@ -156,6 +163,7 @@ async def catalog_product(self, **kwargs) -> WalmartCatalog:
156163
References
157164
----------
158165
https://www.walmart.io/docs/affiliate/catalog-product
166+
159167
"""
160168
if "nextPage" in kwargs:
161169
url = "https://developer.api.walmart.com" + kwargs.pop("nextPage")
@@ -166,7 +174,8 @@ async def catalog_product(self, **kwargs) -> WalmartCatalog:
166174
return WalmartCatalog(response)
167175

168176
async def post_browsed_products(self, itemId: str) -> list[WalmartProduct]:
169-
"""Post Browsed Products Endpoint.
177+
"""
178+
Post Browsed Products Endpoint.
170179
171180
Allows you to recommend products to someone based on their product viewing history.
172181
@@ -196,13 +205,15 @@ async def post_browsed_products(self, itemId: str) -> list[WalmartProduct]:
196205
References
197206
----------
198207
https://www.walmart.io/docs/affiliate/post-browsed-products
208+
199209
"""
200210
url = f"{self.ENDPOINT}/affil/product/v2/postbrowse?itemId={itemId}"
201211
response = await self._send_request(url)
202212
return [WalmartProduct(item) for item in response]
203213

204214
async def product_lookup(self, ids: str | list[str], **kwargs) -> list[WalmartProduct]:
205-
"""Walmart product lookup.
215+
"""
216+
Walmart product lookup.
206217
207218
For more info: (https://walmart.io/docs/affiliate/product-lookup)
208219
@@ -228,6 +239,7 @@ async def product_lookup(self, ids: str | list[str], **kwargs) -> list[WalmartPr
228239
References
229240
----------
230241
https://www.walmart.io/docs/affiliate/product-lookup
242+
231243
"""
232244
url = self.ENDPOINT + "/affil/product/v2/items"
233245

@@ -251,7 +263,8 @@ async def product_lookup(self, ids: str | list[str], **kwargs) -> list[WalmartPr
251263
async def bulk_product_lookup(
252264
self, ids: str | list[str], amount: int = 20, retries: int = 1, **kwargs
253265
):
254-
"""Walmart product lookup for a bulk of products.
266+
"""
267+
Walmart product lookup for a bulk of products.
255268
256269
It will keep going even if there are errors
257270
This function is a generator that gives you #amount products at a time
@@ -290,6 +303,7 @@ async def bulk_product_lookup(
290303
References
291304
----------
292305
https://www.walmart.io/docs/affiliate/product-lookup
306+
293307
"""
294308
url = self.ENDPOINT + "/affil/product/v2/items"
295309

@@ -316,7 +330,8 @@ async def bulk_product_lookup(
316330
log.error(e)
317331

318332
async def product_recommendation(self, itemId: str) -> list[WalmartProduct]:
319-
"""Product Recommendation Endpoint.
333+
"""
334+
Product Recommendation Endpoint.
320335
321336
Extension driven by the science that powers the recommended products container on
322337
Walmart.com. Walmart has parsed 100s of millions of transactions over their product
@@ -346,13 +361,15 @@ async def product_recommendation(self, itemId: str) -> list[WalmartProduct]:
346361
References
347362
----------
348363
https://www.walmart.io/docs/affiliate/product-recommendation
364+
349365
"""
350366
url = f"{self.ENDPOINT}/affil/product/v2/nbp?itemId={itemId}"
351367
response = await self._send_request(url)
352368
return [WalmartProduct(item) for item in response]
353369

354370
async def reviews(self, itemId: str, **kwargs) -> WalmartReviewResponse:
355-
"""Reviews Endpoint.
371+
"""
372+
Reviews Endpoint.
356373
357374
Gives you access to the extensive item reviews on Walmart that have been written by the
358375
users of Walmart.com. This is great content for enriching item descriptions. You are free
@@ -378,6 +395,7 @@ async def reviews(self, itemId: str, **kwargs) -> WalmartReviewResponse:
378395
References
379396
----------
380397
https://www.walmart.io/docs/affiliate/product-recommendation
398+
381399
"""
382400
if "nextPage" in kwargs:
383401
page = kwargs.pop("nextPage").split("page=")[1]
@@ -388,7 +406,8 @@ async def reviews(self, itemId: str, **kwargs) -> WalmartReviewResponse:
388406
return WalmartReviewResponse(response)
389407

390408
async def search(self, query: str, **kwargs) -> WalmartSearch:
391-
"""Search Endpoint.
409+
"""
410+
Search Endpoint.
392411
393412
Text search on the Walmart.com catalog and returns matching items available for sale online.
394413
@@ -443,6 +462,7 @@ async def search(self, query: str, **kwargs) -> WalmartSearch:
443462
References
444463
----------
445464
https://walmart.io/docs/affiliate/search
465+
446466
"""
447467
if "facet" in kwargs:
448468
facet = kwargs["facet"]
@@ -463,7 +483,8 @@ async def search(self, query: str, **kwargs) -> WalmartSearch:
463483
return WalmartSearch(response)
464484

465485
async def stores(self, **kwargs) -> list[WalmartStore]:
466-
"""Store Locator Endpoint.
486+
"""
487+
Store Locator Endpoint.
467488
468489
Locate nearest Walmart Stores via API. It lets users search for stores by
469490
latitude and longitude, and by zip code.
@@ -478,6 +499,7 @@ async def stores(self, **kwargs) -> list[WalmartStore]:
478499
Returns
479500
-------
480501
store ('WalmartStore') : closest store to specified location
502+
481503
"""
482504
if not (("lat" in kwargs and "lon" in kwargs) or ("zip" in kwargs)):
483505
raise ValueError("Missing lat & lon OR zip parameter")
@@ -487,7 +509,8 @@ async def stores(self, **kwargs) -> list[WalmartStore]:
487509
return [WalmartStore(store) for store in response]
488510

489511
async def taxonomy(self, **kwargs) -> WalmartTaxonomy:
490-
"""Taxonomy Endpoint.
512+
"""
513+
Taxonomy Endpoint.
491514
492515
Taxonomy used to categorize items on Walmart.com.
493516
@@ -505,12 +528,14 @@ async def taxonomy(self, **kwargs) -> WalmartTaxonomy:
505528
----------
506529
**kwargs
507530
unknown; WalmartIO documentation does not expose what the acceptable
531+
508532
"""
509533
url = self.ENDPOINT + "/affil/product/v2/taxonomy"
510534
return WalmartTaxonomy(await self._send_request(url, **kwargs))
511535

512536
async def trending(self, publisherId=None) -> list[WalmartProduct]:
513-
"""Trending Items Endpoint.
537+
"""
538+
Trending Items Endpoint.
514539
515540
The Trending Items API is designed to give the information on what is bestselling on
516541
Walmart.com right now. The items returned by this service are a curated list based on the
@@ -527,6 +552,7 @@ async def trending(self, publisherId=None) -> list[WalmartProduct]:
527552
-------
528553
products: list of `WalmartProduct`
529554
a list of walmart products on the trending list
555+
530556
"""
531557
url = self.ENDPOINT + "/affil/product/v2/trends"
532558

@@ -538,7 +564,8 @@ async def trending(self, publisherId=None) -> list[WalmartProduct]:
538564

539565
@_ttl_cache(maxsize=2, ttl=170)
540566
def _get_headers(self) -> dict:
541-
"""Get the headers required for making an API call.
567+
"""
568+
Get the headers required for making an API call.
542569
543570
References
544571
----------
@@ -552,6 +579,7 @@ def _get_headers(self) -> dict:
552579
'WM_SEC.AUTH_SIGNATURE' : signature_enc,
553580
'WM_SEC.KEY_VERSION' : keyVersion
554581
}
582+
555583
"""
556584
timeInt = int(time.time() * 1000)
557585

@@ -582,7 +610,8 @@ def _get_headers(self) -> dict:
582610
return self.headers
583611

584612
async def _send_request(self, url, **kwargs) -> Any:
585-
"""Send a request to the Walmart API and return the HTTP response.
613+
"""
614+
Send a request to the Walmart API and return the HTTP response.
586615
587616
Format is json by default and cannot be changed through kwargs. xml is deprecated.
588617
Send richAttributes='true' by default. Can be set to 'false' through kwargs
@@ -603,6 +632,7 @@ async def _send_request(self, url, **kwargs) -> Any:
603632
InvalidRequestException:
604633
If the response's status code is different than 200 or 201,
605634
raise an InvalidRequestException with the appropriate code
635+
606636
"""
607637
log.debug(f"Making connection to {url}")
608638

@@ -645,7 +675,8 @@ async def _send_request(self, url, **kwargs) -> Any:
645675
raise InvalidRequestException(status_code)
646676

647677
def _validate_call(self) -> bool:
648-
"""Check if the caller has API calls remaining.
678+
"""
679+
Check if the caller has API calls remaining.
649680
650681
If there are remaining calls, check to see if the headers need to be updated.
651682
If so, update them.
@@ -654,6 +685,7 @@ def _validate_call(self) -> bool:
654685
-------
655686
bool:
656687
if there are still remaining calls for the day
688+
657689
"""
658690
if datetime.datetime.now() > self._update_daily_calls_time:
659691
self.daily_calls_remaining = self.daily_calls

0 commit comments

Comments
 (0)