Download tools/ebay.py from 1990two/XTOOLS: direct link, hf CLI and curl.
- Browser
- Download file 1.81 kB
-
https://huggingface.co/spaces/1990two/XTOOLS/resolve/main/tools/ebay.py
- Command line
-
hf download hf://spaces/1990two/XTOOLS/tools/ebay.py
-
curl -L -o ebay.py https://huggingface.co/spaces/1990two/XTOOLS/resolve/main/tools/ebay.py
1.81 kB
| """ | |
| eBay -- Finding API (App ID only, JSON response). | |
| """ | |
| import httpx | |
| from supabase_client import require_tool_keys | |
| BASE = "https://svcs.ebay.com/services/search/FindingService/v1" | |
| def run(params: dict) -> dict: | |
| creds = require_tool_keys("ebay") | |
| app_id = creds["api_key"] | |
| keywords = params.get("keywords") | |
| if not keywords: | |
| raise ValueError("keywords is required") | |
| operation = "findCompletedItems" if params.get("sold_only") else "findItemsByKeywords" | |
| query = { | |
| "OPERATION-NAME": operation, | |
| "SERVICE-VERSION": "1.13.0", | |
| "SECURITY-APPNAME": app_id, | |
| "RESPONSE-DATA-FORMAT": "JSON", | |
| "keywords": keywords, | |
| "paginationInput.entriesPerPage": min(int(params.get("max_results", 25)), 100), | |
| } | |
| if params.get("condition"): | |
| query["itemFilter(0).name"] = "Condition" | |
| query["itemFilter(0).value"] = params["condition"] | |
| resp = httpx.get(BASE, params=query, timeout=15.0) | |
| resp.raise_for_status() | |
| data = resp.json() | |
| key = f"{operation}Response" | |
| items = [] | |
| try: | |
| items = data[key][0]["searchResult"][0].get("item", []) | |
| except Exception: | |
| pass | |
| results = [] | |
| for it in items: | |
| price = it.get("sellingStatus", [{}])[0].get("currentPrice", [{}])[0] | |
| results.append( | |
| { | |
| "title": it.get("title", [None])[0], | |
| "price": price.get("__value__"), | |
| "currency": price.get("@currencyId"), | |
| "condition": it.get("condition", [{}])[0].get("conditionDisplayName", [None])[0], | |
| "end_time": it.get("listingInfo", [{}])[0].get("endTime", [None])[0], | |
| "url": it.get("viewItemURL", [None])[0], | |
| } | |
| ) | |
| return {"count": len(results), "results": results} | |