Rename Ebay items to be more general
This commit is contained in:
parent
446178fc2e
commit
6a7f408d19
@ -5,7 +5,7 @@ from immutabledict import immutabledict
|
|||||||
|
|
||||||
|
|
||||||
@attr.s(auto_attribs=True)
|
@attr.s(auto_attribs=True)
|
||||||
class EbayItemSummary:
|
class ItemSummary:
|
||||||
# arbitrary ID
|
# arbitrary ID
|
||||||
id: str
|
id: str
|
||||||
href: str
|
href: str
|
||||||
@ -25,19 +25,19 @@ class EbayItemSummary:
|
|||||||
|
|
||||||
|
|
||||||
@attr.s(auto_attribs=True)
|
@attr.s(auto_attribs=True)
|
||||||
class EbayMultiItemModelAxis:
|
class MultiItemModelAxis:
|
||||||
code_name: str
|
code_name: str
|
||||||
# human_name: str
|
# human_name: str
|
||||||
values: Dict[int, str]
|
values: Dict[int, str]
|
||||||
|
|
||||||
|
|
||||||
@attr.s(auto_attribs=True)
|
@attr.s(auto_attribs=True)
|
||||||
class EbayItemDetails:
|
class ItemDetails:
|
||||||
seller_name: str
|
seller_name: str
|
||||||
seller_score: int
|
seller_score: int
|
||||||
seller_percentage: str
|
seller_percentage: str
|
||||||
|
|
||||||
axes: Dict[str, EbayMultiItemModelAxis]
|
axes: Dict[str, MultiItemModelAxis]
|
||||||
# variants: Dict[immutabledict[str, int]]
|
# variants: Dict[immutabledict[str, int]]
|
||||||
variants: Dict[immutabledict, int]
|
variants: Dict[immutabledict, int]
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ from typing import List, Dict
|
|||||||
from immutabledict import immutabledict
|
from immutabledict import immutabledict
|
||||||
from requests import Session
|
from requests import Session
|
||||||
|
|
||||||
from fleabay.definitions import EbayItemSummary, EbayItemDetails, EbayMultiItemModelAxis
|
from fleabay.definitions import ItemSummary, ItemDetails, MultiItemModelAxis
|
||||||
from fleabay.utils import chunker, decimal_price_to_pence
|
from fleabay.utils import chunker, decimal_price_to_pence
|
||||||
|
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ class EbayApiExtractor:
|
|||||||
self.api_key = api_key
|
self.api_key = api_key
|
||||||
self.session = Session()
|
self.session = Session()
|
||||||
|
|
||||||
def search(self, term: str, items_per_page: int = 200, remote_lowest_first: bool = False) -> List[EbayItemSummary]:
|
def search(self, term: str, items_per_page: int = 200, remote_lowest_first: bool = False) -> List[ItemSummary]:
|
||||||
url = "https://svcs.ebay.com/services/search/FindingService/v1"
|
url = "https://svcs.ebay.com/services/search/FindingService/v1"
|
||||||
params = {
|
params = {
|
||||||
"SECURITY-APPNAME": self.api_key,
|
"SECURITY-APPNAME": self.api_key,
|
||||||
@ -88,7 +88,7 @@ class EbayApiExtractor:
|
|||||||
if item_id == "154280943581":
|
if item_id == "154280943581":
|
||||||
pprint.pprint(result)
|
pprint.pprint(result)
|
||||||
|
|
||||||
item = EbayItemSummary(
|
item = ItemSummary(
|
||||||
item_id, view_url, result["title"][0], condition,
|
item_id, view_url, result["title"][0], condition,
|
||||||
item_pence, -42, None if is_buy_it_now else bid_count, result["country"][0], postage_pence, result["galleryURL"][0]
|
item_pence, -42, None if is_buy_it_now else bid_count, result["country"][0], postage_pence, result["galleryURL"][0]
|
||||||
)
|
)
|
||||||
@ -106,10 +106,10 @@ class EbayApiExtractor:
|
|||||||
return items
|
return items
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def details(summary: EbayItemSummary) -> EbayItemDetails:
|
def details(summary: ItemSummary) -> ItemDetails:
|
||||||
return summary.extras["details"]
|
return summary.extras["details"]
|
||||||
|
|
||||||
def details_batch(self, ids: List[str]) -> Dict[str, EbayItemDetails]:
|
def details_batch(self, ids: List[str]) -> Dict[str, ItemDetails]:
|
||||||
# eBay can do up to 20 items at once.
|
# eBay can do up to 20 items at once.
|
||||||
result = dict()
|
result = dict()
|
||||||
for id_chunk in chunker(ids, 20):
|
for id_chunk in chunker(ids, 20):
|
||||||
@ -148,7 +148,7 @@ class EbayApiExtractor:
|
|||||||
max_pence = base_pence
|
max_pence = base_pence
|
||||||
|
|
||||||
variants_dict = dict()
|
variants_dict = dict()
|
||||||
axes: Dict[str, EbayMultiItemModelAxis] = dict()
|
axes: Dict[str, MultiItemModelAxis] = dict()
|
||||||
axes_inverse: Dict[str, Dict[str, int]] = dict()
|
axes_inverse: Dict[str, Dict[str, int]] = dict()
|
||||||
|
|
||||||
variations = item_dict.get("Variations")
|
variations = item_dict.get("Variations")
|
||||||
@ -160,7 +160,7 @@ class EbayApiExtractor:
|
|||||||
axes_inverse[axis["Name"]] = {
|
axes_inverse[axis["Name"]] = {
|
||||||
val: i for i, val in enumerate(axis["Value"])
|
val: i for i, val in enumerate(axis["Value"])
|
||||||
}
|
}
|
||||||
axes[axis["Name"]] = EbayMultiItemModelAxis(axis["Name"], dict(enumerate(axis["Value"])))
|
axes[axis["Name"]] = MultiItemModelAxis(axis["Name"], dict(enumerate(axis["Value"])))
|
||||||
|
|
||||||
for variation in variations["Variation"]:
|
for variation in variations["Variation"]:
|
||||||
quantity = variation["Quantity"] - variation["SellingStatus"].get("QuantitySold", 0)
|
quantity = variation["Quantity"] - variation["SellingStatus"].get("QuantitySold", 0)
|
||||||
@ -199,7 +199,7 @@ class EbayApiExtractor:
|
|||||||
extras["min_price"] = int(min_pence)
|
extras["min_price"] = int(min_pence)
|
||||||
extras["max_price"] = int(max_pence)
|
extras["max_price"] = int(max_pence)
|
||||||
|
|
||||||
result[item_id] = EbayItemDetails(
|
result[item_id] = ItemDetails(
|
||||||
seller_dict["UserID"],
|
seller_dict["UserID"],
|
||||||
int(seller_dict["FeedbackScore"]),
|
int(seller_dict["FeedbackScore"]),
|
||||||
seller_dict["PositiveFeedbackPercent"],
|
seller_dict["PositiveFeedbackPercent"],
|
||||||
|
@ -10,7 +10,7 @@ from immutabledict import immutabledict
|
|||||||
from requests import Session
|
from requests import Session
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from fleabay.definitions import EbayItemSummary, EbayItemDetails, EbayMultiItemModelAxis
|
from fleabay.definitions import ItemSummary, ItemDetails, MultiItemModelAxis
|
||||||
|
|
||||||
|
|
||||||
class EbayExtractor:
|
class EbayExtractor:
|
||||||
@ -18,7 +18,7 @@ class EbayExtractor:
|
|||||||
self.domain = domain
|
self.domain = domain
|
||||||
self.session = Session()
|
self.session = Session()
|
||||||
|
|
||||||
def search(self, term: str, items_per_page: int = 200, remote_lowest_first: bool = False) -> List[EbayItemSummary]:
|
def search(self, term: str, items_per_page: int = 200, remote_lowest_first: bool = False) -> List[ItemSummary]:
|
||||||
params = {
|
params = {
|
||||||
"_nkw": term,
|
"_nkw": term,
|
||||||
"_sacat": 0,
|
"_sacat": 0,
|
||||||
@ -106,7 +106,7 @@ class EbayExtractor:
|
|||||||
image_src = image_tag.attrs["src"]
|
image_src = image_tag.attrs["src"]
|
||||||
|
|
||||||
results.append(
|
results.append(
|
||||||
EbayItemSummary(
|
ItemSummary(
|
||||||
link_href,
|
link_href,
|
||||||
link_href,
|
link_href,
|
||||||
title,
|
title,
|
||||||
@ -122,7 +122,7 @@ class EbayExtractor:
|
|||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def details(self, summary: EbayItemSummary) -> EbayItemDetails:
|
def details(self, summary: ItemSummary) -> ItemDetails:
|
||||||
page = self.session.get(summary.href)
|
page = self.session.get(summary.href)
|
||||||
line: bytes
|
line: bytes
|
||||||
for line in page.iter_lines():
|
for line in page.iter_lines():
|
||||||
@ -184,9 +184,9 @@ class EbayExtractor:
|
|||||||
for value in model["menuItemValueIds"]:
|
for value in model["menuItemValueIds"]:
|
||||||
value_map[value] = item_map[value]
|
value_map[value] = item_map[value]
|
||||||
|
|
||||||
axes[model["name"]] = EbayMultiItemModelAxis(model["name"], value_map)
|
axes[model["name"]] = MultiItemModelAxis(model["name"], value_map)
|
||||||
|
|
||||||
return EbayItemDetails("", -1, "-1%", axes, prices)
|
return ItemDetails("", -1, "-1%", axes, prices)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -7,7 +7,7 @@ from quart import Quart, render_template, request
|
|||||||
from wtforms_async import Form, StringField, BooleanField, SelectField
|
from wtforms_async import Form, StringField, BooleanField, SelectField
|
||||||
|
|
||||||
from fleabay.extractors.ebay_api_extractor import EbayApiExtractor
|
from fleabay.extractors.ebay_api_extractor import EbayApiExtractor
|
||||||
from fleabay.definitions import EbayItemDetails
|
from fleabay.definitions import ItemDetails
|
||||||
from fleabay.extractors.ebay_raw_extractor import EbayExtractor
|
from fleabay.extractors.ebay_raw_extractor import EbayExtractor
|
||||||
|
|
||||||
app = Quart(__name__)
|
app = Quart(__name__)
|
||||||
@ -79,10 +79,10 @@ async def search():
|
|||||||
futs = tuple(item_details_fut.keys())
|
futs = tuple(item_details_fut.keys())
|
||||||
detail_results = await asyncio.gather(*futs, return_exceptions=True)
|
detail_results = await asyncio.gather(*futs, return_exceptions=True)
|
||||||
|
|
||||||
item_details: Dict[str, EbayItemDetails] = {
|
item_details: Dict[str, ItemDetails] = {
|
||||||
item_details_fut[fut]: res
|
item_details_fut[fut]: res
|
||||||
for res, fut in zip(detail_results, futs)
|
for res, fut in zip(detail_results, futs)
|
||||||
if isinstance(res, EbayItemDetails)
|
if isinstance(res, ItemDetails)
|
||||||
}
|
}
|
||||||
axes_errors = {
|
axes_errors = {
|
||||||
item_details_fut[fut]: str(res)
|
item_details_fut[fut]: str(res)
|
||||||
|
Loading…
Reference in New Issue
Block a user