def ebay_api_data(input_list, time_string, real=1): if (real == 1): f = open('./data/' + time_string[:-6] + 'ebay_gc', 'w+') else: f = open('./data/' + time_string[:-6] + 'all_ebay_gc', 'w+') f.write("[") res = dict() size = len(input_list) try: api = Finding(appid="YuHUANG-insightd-PRD-04d8cb02c-4739185d") for i in xrange(0, size): cur_list = input_list[i] # print cur_list[0] if (cur_list[0] != 'soak-&-sleep'): response = api.execute( 'findItemsAdvanced', {'keywords': cur_list[0] + ' Gift Card'}) join_string = str(response.dict()) if (i != size - 1): f.write(json.dumps(response.dict())) f.write(",\n") else: f.write(json.dumps(response.dict())) f.write("\n") f.write("]") f.close() except ConnectionError as e: print(e) print(e.response.dict())
def getFindingApiSession(): if not hasattr(thread_local_FindingApi_Session,"api"): thread_local_FindingApi_Session.api=Finding(config_file=None, domain='svcs.ebay.com', appid="SatyaPra-MyEBPrac-PRD-abce464fb-dd2ae5fe", devid="6c042b69-e90f-4897-9045-060858248665", certid="PRD-bce464fbd03b-273a-4416-a299-7d41" ) return thread_local_FindingApi_Session.api
def findOne(d, fh): try: api = Finding(appid="EdisonLi-syrup-PRD-c8e35c535-b071148d", config_file=None) response = api.execute( 'findItemsAdvanced', { 'keywords': d['keywords'], 'itemFilter': d['itemFilter'], 'paginationInput': { 'entriesPerPage': '25', 'pageNumber': '1' }, 'sortOrder': 'PricePlusShippingLowest' }) fh.write('<h3> Keywords: ' + d['keywords'] + '</h3>\n') fh.write('<table border="1">\n') for item in response.reply.searchResult.item: fh.write( "<tr><th>%s</th><th>%s %s</th><th>%s</th><th><a href=%s>click</a></th>\n" % (item.itemId, item.sellingStatus.currentPrice.value, item.sellingStatus.currentPrice._currencyId, item.title, item.viewItemURL)) fh.write('</table>\n') except ConnectionError as e: print(e) print(e.response.dict())
def category(id): from ebaysdk.finding import Connection as Finding from ebaysdk.exception import ConnectionError api = Finding( domain = 'svcs.ebay.com', appid=app_id, config_file=None, siteid="EBAY-US" ) callData = { "categoryId": id, "outputSelector": ["GalleryInfo","PictureURLLarge"] } response = api.execute('findItemsByCategory', callData) print(response) data = "<html><head><script>window._epn = {campaign:5338177835};</script><script src=\"https://epnt.ebay.com/static/epn-smart-tools.js\"></script></head><body><ul>" for i in response.dict()["searchResult"]["item"]: #{'itemId': '231505660468', 'title': 'Police Magnum mace pepper spray 1/2oz hot pink actuator self defense protection', 'globalId': 'EBAY-US', 'primaryCategory': {'categoryId': '79849', 'categoryName': 'Pepper Spray'}, 'galleryURL': 'http://thumbs1.ebaystatic.com/m/mYIVyE88preQeEP4Zxe1kNw/140.jpg', 'galleryInfoContainer': {'galleryURL': [{'_gallerySize': 'Large', 'value': 'http://thumbs1.ebaystatic.com/m/mYIVyE88preQeEP4Zxe1kNw/140.jpg'}, {'_gallerySize': 'Medium', 'value': 'http://thumbs1.ebaystatic.com/m/mYIVyE88preQeEP4Zxe1kNw/96.jpg'}, {'_gallerySize': 'Small', 'value': 'http://thumbs1.ebaystatic.com/m/mYIVyE88preQeEP4Zxe1kNw/80.jpg'}]}, 'viewItemURL': 'http://www.ebay.com/itm/Police-Magnum-mace-pepper-spray-1-2oz-hot-pink-actuator-self-defense-protection-/231505660468', 'paymentMethod': 'PayPal', 'autoPay': 'false', 'postalCode': '32829', 'location': 'Orlando,FL,USA', 'country': 'US', 'shippingInfo': {'shippingServiceCost': {'_currencyId': 'USD', 'value': '0.0'}, 'shippingType': 'Free', 'shipToLocations': 'Worldwide', 'expeditedShipping': 'false', 'oneDayShippingAvailable': 'false', 'handlingTime': '1'}, 'sellingStatus': {'currentPrice': {'_currencyId': 'USD', 'value': '4.99'}, 'convertedCurrentPrice': {'_currencyId': 'USD', 'value': '4.99'}, 'sellingState': 'Active', 'timeLeft': 'P25DT10H17M37S'}, 'listingInfo': {'bestOfferEnabled': 'false', 'buyItNowAvailable': 'false', 'startTime': '2015-03-15T00:21:19.000Z', 'endTime': '2017-09-30T00:21:19.000Z', 'listingType': 'StoreInventory', 'gift': 'false', 'watchCount': '118'}, 'returnsAccepted': 'true', 'condition': {'conditionId': '1000', 'conditionDisplayName': 'New'}, 'isMultiVariationListing': 'false', 'pictureURLLarge': 'http://i.ebayimg.com/00/s/MTUxMlgxMDc5/z/DpsAAOSwU-pXs2n1/$_1.JPG', 'topRatedListing': 'true'} print(i) if "pictureURLLarge" in i: data+='<li><a href="'+i["viewItemURL"]+'">'+i['title']+'<img src="'+i["pictureURLLarge"]+'" /></a></ul>' data += "</ul></body></html>" return Response(body=data, status_code=404, headers={'Content-Type':'text/html'})
def searchEbay(searchTerms, page_num=1): ebay_pricelist = pd.DataFrame() try: api = Finding(config_file='ebay.yaml', debug=False, siteid="EBAY-US") request = { 'keywords': searchTerms, 'itemFilter': { 'name': 'condition', 'value': 'used' }, 'paginationInput': { 'entriesPerPage': ITEMS_PER_PAGE, # max = 100 'pageNumber': page_num }, } response = api.execute('findItemsByKeywords', request) if int(response.dict()['searchResult']["_count"]) != 0: for item in response.dict()['searchResult']['item']: price = item['sellingStatus']['convertedCurrentPrice']['value'] name = item['title'] info_to_keep = {'price': price, 'name': name} ebay_pricelist = ebay_pricelist.append(info_to_keep, ignore_index=True) ebay_pricelist['price'] = ebay_pricelist['price'].astype(float) except ConnectionError as e: print(e) print(e.response.dict()) return ebay_pricelist
def get_json_data(self, keyword, price_from, price_to): """ Method returns a dictionary with data collected keyword: str - the name of the product user wants to find price_from: str - start of the price range price_to: str - end of the price range return: dict """ try: api = Finding(config_file='ebay.json', appid='Volodymy-Expendit-PRD-3196809ca-9c1b019a') # allows to set the price range itemFilter = [{ "name": "MaxPrice", "value": str(price_to), "paramName": "Currency", "paramValue": "USD" }, { "name": "MinPrice", "value": str(price_from), "paramName": "Currency", "paramValue": "USD" }] request = {'keywords': keyword, 'itemFilter': itemFilter} response = api.execute('findItemsAdvanced', request) return response.dict()['searchResult']['item'] except KeyError: return None
def FindingAPI(search_input, pageNumber): try: api = Finding(config_file='config/ebay.yaml') api_dictionary = { 'keywords': search_input, #'itemFilter' : [ #{'name': 'Condition', 'value': 'Used'}, #{'name': 'MinPrice', 'value': '200', 'paramName': 'Currency', 'paramValue': 'USD'}, #{'name': 'MaxPrice', 'value': '400', 'paramName': 'Currency', 'paramValue': 'USD'}, #], 'pageinationInput': { 'entriesPerPage': '100', 'pageNumber': pageNumber }, 'sortOrder': 'CurrentPriceHighest' } # Execute api HTTP request to ebay and provide dictionary parameters response = api.execute('findCompletedItems', api_dictionary) # Return diction of the HTTP response response = response.dict() return response except ConnectionError as e: print e print e.response.dict()
def get_ebay_postings(city): api = Finding(config_file='ebay.yaml') n_pages = 20 posting_ids = [] for n_page in range(n_pages): api_request = { 'itemFilter': [{ 'name': 'HideDuplicateItems', 'value': True }], 'paginationInput': { 'entriesPer': 100, 'pageNumber': n_page + 1 }, 'sortOrder': 'StartTimeNewest', 'categoryId': '177831', 'Country': 'US', 'ListingStatus': 'Active' } response = api.execute('findItemsAdvanced', api_request) items = response.reply.searchResult.item for item in items: posting_ids.append(item.itemId) return posting_ids
def get_search_items(query, cat, limit=10, page=1): key_name = "seaarch_" + "query_" + str(cat) + "_" + str(limit) + "_" + str( page) result = get_cache(key_name) if result: items = json.loads(result) else: start = time.time() api = Finding(domain='svcs.ebay.com', appid=config.app_id, config_file=None, siteid="EBAY-US") callData = { "categoryId": cat, "outputSelector": ["GalleryInfo", "PictureURLLarge"], "paginationInput": { "entriesPerPage": limit, "pageNumber": page }, "keywords": urllib.request.unquote(query) } items = api.execute('findItemsAdvanced', callData).dict() send_metric("search_items", time.time() - start) set_cache(key_name, json.dumps(items)) return items
def apiCall(keyword, pages, category): # For the range pages = pages + 1 # Initialize the two lists used to store the data prices = [] times = [] result = [] # I acknowledge that this is incredibly slow to get data but ebay will only allow 100 items to be returned per page so I have to call multiple pages for x in range(1, pages): try: api = Finding(appid=str(os.environ['api_key']), config_file=None) response = api.execute( 'findCompletedItems', { 'keywords': keyword, 'categoryId': category, 'paginationInput': { 'pageNumber': x } }) result = response.dict()['searchResult']['item'] except ConnectionError as e: print(e) print(e.response.dict()) for x in result: # Add to relevant fields to their respective lists prices.append(float(x['sellingStatus']['currentPrice']['value'])) # Convert the string to datetime object times.append( datetime.strptime(x['listingInfo']['endTime'], "%Y-%m-%dT%H:%M:%S.%fZ")) return prices, times
def run(): user_UPC = get_UPC() while True: try: ''' input_dictionary contains all the parameters that will be passed to the execute method of the Finding class to search ebay via UPC. productID defines the search for UPCs. paginationInput defines the search response size. ListingType restricts the search to listing types that are associated with 'buy it now' options. LocatedIn restricts the search the the US. sortOrder is set to return the the listings in order from cheapest to more expensive. ''' input_dictionary = { 'productId': { '#text': user_UPC, '@attrs': { 'type': 'UPC' } }, 'paginationInput': { 'entriesPerPage': 100, 'pageNumber': 1 }, 'itemFilter': [{ 'name': 'ListingType', 'value': ['FixedPrice', 'StoreInventory', 'AuctionWithBIN'] }, { 'name': 'LocatedIn', 'value': 'US' } ], 'sortOrder': 'PricePlusShippingLowest' } api = Finding(appid=config.api_key, config_file=None) response = api.execute('findItemsByProduct', input_dictionary) response_dictionary = response.dict() response_search = SearchResponse(response_dictionary) subject = 'Your daily search results for: {}.'.format(user_UPC) try: msg = response_search.prettify_listings_list() except KeyError: print('Sorry no results were found for that UPC, please try a different one.') continue send_email(subject=subject, msg=msg) print('Sleeping for 24 hours. Press \'ctrl + c\' at anytime to exit.') '''KeyboardInterrupt exception facilitates the ability to exit the program at anytime when the program is run from the terminal.''' try: sleep(int(config.wait_time_in_seconds)) except KeyboardInterrupt: exit() except ConnectionError as e: print(e) print(e.response.dict()) print('Something went wrong, please try again later.') exit()
def __init__(self): self.filepath = os.path.dirname(os.path.realpath(__file__)) self.finding_api = Finding(config_file=self.filepath + '/ebay.yaml') # self.search_requests = self.parse_search_config() self.search_requests = self.get_searches() self.cached_results = {} for search in self.search_requests: self.add_search(search)
def findItemsAdvanced(keywords): api = Finding(appid=myAppId, config_file=None) response = api.execute( 'findItemsAdvanced', { 'keywords': keywords, 'categoryId': category, 'sortOrder': 'PricePlusShippingLowest' }) return response.dict()
def connect(self, connection_type="Finding"): if connection_type == "Finding": self.api = Finding(appid=os.getenv("EBAY_API_ID"), siteid='EBAY-GB', config_file=None) elif connection_type == "Shopping": self.api = Shopping(appid=os.getenv("EBAY_API_ID"), siteid='EBAY-GB', config_file=None)
def ebay_find(keyword): from ebaysdk.finding import Connection as Finding api = Finding(domain='svcs.sandbox.ebay.com', appid="MethodDa-MethodDa-SBX-e2ccbdebc-b7307a8f", config_file=None) response = api.execute('findItemsAdvanced', {'keywords': keyword}) ebay_dict = response.dict() return ebay_dict
def init_finding_api(): app_id = "MichaBag-ca6b-45b4-aab0-b1044c2fd03e" find_api = Finding( domain = 'svcs.ebay.com', appid=app_id, config_file=None, siteid="EBAY-US" ) return find_api
def init_finding_api(): global find_api if find_api is None: print("init") find_api = Finding(domain='svcs.ebay.com', appid=config.app_id, config_file=None, siteid="EBAY-US") return find_api
def main(argv): try: api = Finding(appid="SpencerH-sand-PRD-245ed6035-eb73f8e2", config_file=None) keywords = argv[0] response = api.execute('findItemsAdvanced', {'keywords': keywords}) data = response.dict() data = data['searchResult']['item'] maximum = 0 minimum = sys.maxsize price_lst = [] output = [] for product in data: a = dict() a['title'] = product['title'] a['galleryURL'] = product['galleryURL'] a['currencyId'] = product['sellingStatus']['currentPrice'][ '_currencyId'] price = float(product['sellingStatus']['currentPrice']['value']) a['value'] = price price_lst.append(price) if price < minimum: minimum = price if price > maximum: maximum = price output.append(a) avg = numpy.mean(price_lst) median = numpy.median(price_lst) meanSmallestDiff = sys.maxsize medianSmallestDiff = sys.maxsize for i in range(0, len(price_lst)): curPrice = float(output[i]['value']) if curPrice == maximum: maxIndex = i if curPrice == minimum: minIndex = i if numpy.abs(curPrice - avg) < meanSmallestDiff: meanSmallestDiff = numpy.abs(curPrice - avg) meanIndex = i if numpy.abs(curPrice - median) < medianSmallestDiff: medianSmallestDiff = numpy.abs(curPrice - median) medIndex = i final = dict() final['maximum'] = output[maxIndex] final['minimum'] = output[minIndex] final['median'] = output[medIndex] final['mean'] = output[meanIndex] with open('result.json', 'w') as fp: json.dump(final, fp) except ConnectionError as e: print(e) print(e.response.dict())
def collect_api_data(cur): """ query the API and store results """ # load gmail config with open('/home/curtis/etc/gmail') as f: gmail = json.load(f) # set starting values for counters page_num = 1 cnt = 0 while True: try: api = Finding(domain='svcs.ebay.com', config_file='/home/curtis/etc/ebay.yaml') r = api.execute('findCompletedItems', {'categoryId': '6161', 'paginationInput': {'pageNumber': page_num}}) response = r.dict() if response['ack'] == "Success" and 'item' in response['searchResult'].keys(): logger.info("Retreived page: {}".format(page_num)) for ad in response['searchResult']['item']: try: cur.execute("INSERT INTO ebay_api_raw (itemid, ad) VALUES (%s, %s)", [int(ad['itemId']), json.dumps(ad)]) cnt += 1 except Exception as e: break else: logger.info("Issue at page: {} ".format(page_num)) logger.info("Issue: {}".format(response)) break except ConnectionError as e: logger.info("Connection error: {}".format(e.response)) break page_num += 1 # print number of new records inserted into DB logger.info("Number of new records inserted: {}".format(cnt)) # send email user = gmail['gmail_user'] pwd = gmail['gmail_pwd'] recipient = '*****@*****.**' subject = '{} new records from the eBay API'.format(cnt) body = '' send_email(user, pwd, recipient, subject, body)
def __init__(self): try: self.finding_api = Finding(appid='GUANGZHE-ece1779a-PRD-7c62ba413-e3800b20', siteid='EBAY-ENCA', config_file=None) except ConnectionError as e: print(e) print(e.response.dict()) try: self.shopping_api = Shopping(appid='GUANGZHE-ece1779a-PRD-7c62ba413-e3800b20', siteid='EBAY-ENCA', config_file=None) except ConnectionError as e: print(e) print(e.response.dict())
def create(self, validated_data): validated_data['user'] = self.context['request'].user ebay_id = validated_data.get('client_id') try: ebay_search = Finding(appid=ebay_id, config_file=None) response = ebay_search.execute('findItemsAdvanced', {'keywords': 'iphone'}) except ConnectionError as e: raise serializers.ValidationError({ 'message': "The ebay client_id does not exist in domain Ebay, please register another ID" }) ebay = EbayAssociates.objects.create(**validated_data) return ebay
def ebay_search(phrase): api = Finding(domain=CONFIG_EBAY["DOMAIN"], appid=CONFIG_EBAY["APP_ID"], config_file=None) response = api.execute( 'findItemsByKeywords', { 'keywords': phrase, 'sortOrder': 'PricePlusShippingLowest', 'paginationInput': { 'entriesPerPage': 20, 'pageNumber': 1 } }) return response.dict().get("searchResult", {}).get("item", [])
def ebay_link(keyword): try: api = Finding(appid="SurajKho-hackutd-PRD-cdc74433e-5e966209", config_file=None) response = api.execute('findItemsAdvanced', {'keywords': 'toilet paper'}) c = (response.dict()['searchResult']['item']) result_link = [] for item in range(10): result_link.append(c[item]['viewItemURL']) except ConnectionError as e: print(e) print(e.response.dict()) return result_link
def fetch(keywords): api = Finding(appid="SpencerH-sand-PRD-245ed6035-eb73f8e2", config_file=None) response = api.execute('findItemsAdvanced', {'keywords': keywords}) data = response.dict() data = data['searchResult']['item'] maximum = 0 minimum = sys.maxsize price_lst = [] output = [] for product in data: a = dict() a['title'] = product['title'] a['galleryURL'] = product['galleryURL'] a['currencyId'] = product['sellingStatus']['currentPrice']['_currencyId'] price = float(product['sellingStatus']['currentPrice']['value']) a['value'] = price price_lst.append(price) if price < minimum: minimum = price if price > maximum: maximum = price output.append(a) avg = numpy.mean(price_lst) median = numpy.median(price_lst) meanSmallestDiff = sys.maxsize medianSmallestDiff = sys.maxsize for i in range(0, len(price_lst)): curPrice = float(output[i]['value']) if curPrice == maximum: maxIndex = i if curPrice == minimum: minIndex = i if numpy.abs(curPrice - avg) < meanSmallestDiff: meanSmallestDiff = numpy.abs(curPrice - avg) meanIndex = i if numpy.abs(curPrice - median) < medianSmallestDiff: medianSmallestDiff = numpy.abs(curPrice - median) medIndex = i final = dict() final['maximum'] = output[maxIndex] final['minimum'] = output[minIndex] final['median'] = output[medIndex] final['mean'] = output[meanIndex] returnvalue = final channel.basic_publish(exchange='', routing_key='completed_queue', body=returnvalue)
def findingAPI(page, earlierDay, nowTime, categoryID): ### Reference config file to get APPID api = Finding(config_file='config/ebay.yaml') # Setup api_request options to later pass to api execution api_request = { 'categoryId': categoryID, 'itemFilter': [ { 'name': 'MinPrice', 'value': '30' }, # Minimum Price { 'name': 'MaxPrice', 'value': '10000' }, # Maximum Price { 'name': 'SoldItemsOnly', 'value': 'True' }, # Show only successfully sold items { 'name': 'LocatedIn', 'value': 'US' }, # Located in United States { 'name': 'StartTimeFrom', 'value': earlierDay }, # Time in UTC format YYYY-MM-DDTHH:MM:SS.000Z (Z for Zulu Time). (e.g: '2018-01-1T08:00:01') { 'name': 'EndTimeTo', 'value': nowTime } # Time in UTC format YYYY-MM-DDTHH:MM:SS.000Z (Z for Zulu Time). (e.g: '2018-01-19T14:30:01') ], 'paginationInput': { 'entriesPerPage': 100, 'pageNumber': page #'pageNumber': '1' # e.g: custom page } } ### Execute against findCompletedItems with designated api_request options api.execute('findCompletedItems', api_request) ### Return results as json form dictionary results = api.response.dict() return results
def single_page_query(self, page_number=1, include_meta_data=True, return_df=False): """ Tests that an initial API connection is successful and returns a list of unnested ebay item dictionaries . If unsuccessful returns a string of the error that occurred. """ parameters = self.create_search_parameters(page_number, include_meta_data) api = Finding(appid=self.api_id, config_file=None, https=True) try: response = api.execute("findItemsAdvanced", parameters) assert response.reply.ack == "Success" except ConnectionError: message = "Connection Error! Ensure that your API key was correctly and you have web connectivity." print(message) return message except AssertionError: try: message = response.dict()["errorMessage"]["error"]["message"] except KeyError: message = ( "There is an API error, check your rate limit or search parameters" ) print(message) return message response = response.dict() if response["paginationOutput"]["totalPages"] == "0": message = f"There are no results for a search of: {self.full_query}" print(message) return message if include_meta_data: self._clean_category_data(response) # Eventually don't want to run these each time... need to check follow through self.total_entries = int(response["paginationOutput"]["totalEntries"]) self.total_pages = int(response["paginationOutput"]["totalPages"]) self.search_url = response["itemSearchURL"] response = [ self.flatten_dict(i) for i in response["searchResult"]["item"] ] if return_df: return pd.DataFrame(response) return response
def search(itemInfo, pageNum): category = itemInfo[2] startDate = itemInfo[1] item = itemInfo[0] try: api = Finding(appid="TaylorMo-1104-4ca1-bc59-34b44b585cf0", config_file=None) if category != None: api_request = { 'keywords': item, 'categoryId': [category], 'itemFilter': [{ 'name': 'SoldItemsOnly', 'value': True }, { 'name': 'LocatedIn', 'value': 'US' }, { 'name': 'EndTimeFrom', 'value': startDate }], 'paginationInput': [{ 'pageNumber': pageNum }] } else: api_request = { 'keywords': item, 'itemFilter': [{ 'name': 'SoldItemsOnly', 'value': True }, { 'name': 'LocatedIn', 'value': 'US' }, { 'name': 'EndTimeFrom', 'value': startDate }], 'paginationInput': [{ 'pageNumber': pageNum }] } response = api.execute('findCompletedItems', api_request) return response.dict() except ConnectionError as e: print(e) print(e.response.dict())
def itemFinder(search_item): try: api = Finding(appid="ScottRus-bf7d-437a-a830-3735324dd553", config_file=None, debug=True) response = api.execute('findItemsAdvanced', {'keywords': search_item}) items = response.dict() SQLConnection.get_Ebay_data(items['searchResult']) ##EbayDbSQL.set_ebay_dict(items['searchResult']) ## item in tings['item']: ## ebay_info = "itemId: {}, title: {}, Selling Status: {}".format(item['itemId'],item['title'],item['sellingStatus']) except KeyError: print KeyError
def _async_pull(self, page_number): parameters = self.create_search_parameters(page_number=page_number, include_meta_data=False) api = Finding(appid=self.api_id, config_file=None, https=True) try: result = api.execute("findItemsAdvanced", parameters) if result.reply.ack == "Success": return [ self.flatten_dict(i) for i in result.dict()["searchResult"]["item"] ] return list() except ConnectionError as error: print(error) return list()
def addCatalog(word, keyWord, request): api = Finding(appid=ID_APP, config_file=None, https=True) response = api.execute('findItemsAdvanced', {'keywords': word, 'paginationInput': [{'entriesPerPage': MAX_ENTRIES}]}) products = response.dict() products = products["searchResult"] i = 0 for product in products["item"]: slug = slugify(product["title"]) num = random.randint(1, 10000) slug += str(num) try: Item.objects.create(title=product["title"], price=float(product["sellingStatus"]["convertedCurrentPrice"]["value"]), imgUrl=product["galleryURL"], condition=product["condition"]["conditionDisplayName"], conditionId=product["condition"]["conditionId"], slug=slug, keyWord=keyWord) except: Item.objects.create(title=product["title"], price=float(product["sellingStatus"]["convertedCurrentPrice"]["value"]), imgUrl=NO_IMAGE, condition='', conditionId=0, slug=slug, keyWord=keyWord)