Created
November 3, 2018 14:29
-
-
Save jakekara/30b90042dc2052911239eaf79cf571f4 to your computer and use it in GitHub Desktop.
Search for products on searspartsdirect.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bash-3.2$ python sears-parts.py "door handle" | |
WP8519336 Dryer door handle pad | |
8519373 Dryer door handle screw hole plug (graphite) | |
8519374 Dryer door handle screw hole plug (black) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, json | |
from sys import argv | |
class PartSearch: | |
def __init__(self, | |
brand_id="", | |
model_number="", | |
product_category_id=""): | |
self.brand_id = str(brand_id) | |
self.model_number = str(model_number) | |
self.product_category_id = str(product_category_id) | |
def url(self, term): | |
return "https://searspartsdirectapis.com/pd-services/models/components/parts"\ | |
+ "?modelNumber=%s&brandId=%s&productCategoryId=%s&description=%s" % ( | |
self.model_number, | |
self.brand_id, | |
self.product_category_id, | |
term) | |
def search_for(self, term): | |
response = requests.get( | |
self.url(term)) | |
if response.status_code != 200: | |
raise Exception("ERROR") | |
return response.json() | |
kenmore_dryer = PartSearch( | |
brand_id="0582", | |
model_number = "11082832100", | |
product_category_id = "0151200", | |
) | |
# Print out just the name and part numbers | |
for result in kenmore_dryer.search_for(argv[1])["results"]: | |
print ("%20s\t%s" % (result["partCompositeKey"]["partNumber"], result["description"])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment