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
Exemple #2
0
def search_ebay():
    searchword = request.args.get('q', '')
    for i in colours:
        searchword = searchword.replace(i, '')
    try:
        api = Connection(appid=EBAY_APPID, config_file=None)
        response = api.execute('findItemsAdvanced', {'keywords': searchword})
        #		print int(response.dict()['searchResult']['_count']) == 0
        if int(response.dict()['searchResult']['_count']) == 0:
            return jsonify({"error": "No results found"})
        item = response.reply.searchResult.item[0]
        #		print dir(item)
        pro = "\n\n\n---------------------------------\n"
        pro += "Ebay item name:" + item.title + "\n"
        pro += "Price: " + item.sellingStatus.currentPrice.value + item.sellingStatus.currentPrice._currencyId
        pro += "\n---------------------------------\n"
        write_to_file(pro)
        print pro
        return jsonify({
            "name":
            item.title,
            "price":
            item.sellingStatus.currentPrice.value + ' ' +
            item.sellingStatus.currentPrice._currencyId
        })
    except ConnectionError as e:
        print e
        return jsonify(e.response.dict())
Exemple #3
0
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 ProcessQueryEbay(apikey, query):
        try:
            tempList = []
            api = Connection(appid=apikey, config_file=None)
            response = api.execute('findItemsAdvanced', {'keywords': query})

            if hasattr(response.reply.searchResult, 'item'):
                for item in response.reply.searchResult.item:
                    tempDict = {}
                    tempDict[CStaticConsts.siteName] = CStaticConsts.Ebay
                    tempDict[CStaticConsts.title] = item.title
                    tempDict[
                        CStaticConsts.
                        currencyType] = item.sellingStatus.currentPrice._currencyId
                    tempDict[CStaticConsts.
                             itemPrice] = item.sellingStatus.currentPrice.value
                    tempDict[CStaticConsts.productUrl] = item.viewItemURL

                    tempList.append(tempDict)

                return tempList

        except ConnectionError as e:
            print(e)
            print(e.response.dict())
        except Exception as e:
            print('Error: getebaylistings threw exception. Message: ', e)
def apiCall(keywords, min, max, listing):
    api = Connection(config_file=r'ebay.yaml', debug=True, siteid="EBAY-US")

    request = {
        'keywords':
        keywords,
        'itemFilter': [{
            'name': 'MinPrice',
            'value': min
        }, {
            'name': 'MaxPrice',
            'value': max
        }, {
            'name': 'ListingType',
            'value': listing
        }],
        'paginationInput': {
            'entriesPerPage': 10,
            'pageNumber': 1
        },
        'sortOrder':
        'PricePlusShippingLowest'
    }

    return api.execute('findItemsByKeywords', request)
Exemple #6
0
 def __init__(self, config):
     self._config = config
     self._client = Connection(domain=self._config['domain'], debug=False,
                               appid=self._config['appid'],
                               config_file=None,
                               siteid=self._config['siteid'])
     self._logger = logging.getLogger(__name__)
def get_items(appid, search_keyword, categoryId):
    results = []
    try:
        api = Connection(appid=appid, config_file=None)
        response = api.execute('findItemsAdvanced', {
            'keywords': search_keyword
        }).json()

        item_dict = json.loads(response)
        items = item_dict['searchResult']['item']

        for item in items:
            c_id = item['primaryCategory']['categoryId']
            if c_id != categoryId:
                continue
            autoPay = bool_to_bit(item['autoPay'])
            currentPrice = float(
                item['sellingStatus']['currentPrice']['value'])
            condition = float(item['condition']['conditionId'])
            results.append({
                'input': (autoPay, condition),
                'price': currentPrice
            })

    except ConnectionError as e:
        print(e)
        print(e.response.dict())

    return results
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
Exemple #9
0
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'})
Exemple #10
0
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
Exemple #11
0
def runQuery(page):
    try:
        api = Connection(appid=ebayAppID, config_file=None)
        response = api.execute(
            'findItemsAdvanced', {
                'keywords':
                'pokemon online code',
                'itemFilter': [{
                    'name': 'ListingType',
                    'value': ['FixedPrice', 'AuctionWithBIN']
                }, {
                    'name': 'FreeShippingOnly',
                    'value': 'true'
                }, {
                    'name': 'MinPrice',
                    'value': '5',
                    'paramName': 'Currency',
                    'paramValue': 'USD'
                }, {
                    'name': 'MaxPrice',
                    'value': '50',
                    'paramName': 'Currency',
                    'paramValue': 'USD'
                }],
                'paginationInput': {
                    'entriesPerPage': 50,
                    'pageNumber': page
                },
                'sortOrder':
                'StartTimeNewest'
            })
    except ConnectionError as e:
        print(e)
        print(e.response.dict())
    return response.dict()
Exemple #12
0
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())
Exemple #13
0
def ebay_api(search):
	try:
		api = Connection(appid='nyetmoi-zooccs-PRD-ef8fc7c73-6322fe73', config_file=None)
		response = api.execute('findItemsAdvanced', {'keywords': search})
		items = response.reply.searchResult.item
		avg = 0
		cost = 0
		urls = []
		flagged =[]
		for i in range(len(items)):
			cost += float(items[i].sellingStatus.currentPrice.value)
			urls.append(items[i].viewItemURL)
		avg = float(cost)/len(items)	
		print len(items)
		signed_variances = []
		for i in range(len(items)):
			signed_variances.append(float(items[i].sellingStatus.currentPrice.value)-avg)
		#signed_variances.sort()
		second_avg = sum(signed_variances)/len(items)
		signed_second_variances = []
		for i in range(len(items)):
			signed_second_variances.append(((signed_variances[i]-second_avg)/avg))
			if (signed_second_variances[-1]>7.5):
				flagged.append(items[i])
		signed_second_variances.sort()
		print len(flagged)
		#print signed_second_variances
		return flagged


	except ConnectionError as e:
	    print e
	    print e.response.dict()
Exemple #14
0
def commence_search(card_list, setname, grade):
    for card_name in card_list:
        try:
            api = Connection(appid='vincentc-pokemon-PRD-5f95f0a8e-eb74953b',
                             config_file=None)
            response = api.execute('findItemsByKeywords',
                                   {'keywords': 'mew ex play promo'})

            assert (response.reply.ack == 'Success')
            assert (type(response.reply.timestamp) == datetime.datetime)
            assert (type(response.reply.searchResult.item) == list)
            item = response.reply.searchResult.item

            search_results = response.dict()

            item = response.reply.searchResult.item[0]
            assert (type(item.listingInfo.endTime) == datetime.datetime)
            assert (type(response.dict()) == dict)
            #print (len(k['searchResult']['item']))
            print(search_results['searchResult']['item'][0]['itemId'])

        except ConnectionError as e:

            print(e)
            print(e.response.dict())

    pass
Exemple #15
0
    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 __init__(self, id_dict, config):

        self.id_dict = id_dict

        self.err_cnt = 0
        self.tm_last_err = 0
        self.dict_needs_update = 0
        self.crnt_found_items = 0
        self.crnt_srch_key = ''
        self.crnt_srch_type = ''
        self.stats = {}

        self.delay = config['delay']
        self.srch_conf_lst = config['srch']

        self.ids_file = config['ids']
        self.stats_file = config['stats']
        self.err_file = config['errlog']

        self.appid = config['rbt']['appid']
        self.ya_host = config['rbt']['ya_host']
        self.ya_port = config['rbt']['ya_port']
        self.ya_usr = config['rbt']['ya_usr']
        self.ya_pwd = config['rbt']['ya_pwd']
        self.from_email = config['rbt']['from_email']
        self.to_email = config['rbt']['to_email']

        self.api = Connection(appid=self.appid, config_file=None)
Exemple #17
0
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
Exemple #18
0
 def fetch_product(self, identifier):
     self.api = Connection(appid=self.appID, config_file=None)
     args = {
         'keywords': identifier
     }
     response = self.api.execute('findItemsAdvanced', args)
     return response if response.reply.ack == "Success" else None
Exemple #19
0
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()
Exemple #20
0
def call_Ebay_API(page_num, search_keywords, try_count=1):
    try:
        api = Connection(appid='MattDass-FLCompar-PRD-12442a3e5-6825c4fa',
                         config_file=None)
        response = api.execute(
            'findItemsAdvanced', {
                'keywords': search_keywords,
                'paginationInput': {
                    'pageNumber': page_num
                }
            })
        dictstr = api.response.dict()
        df = pd.DataFrame(dictstr)

        # for i in dictstr['searchResult']['item']:
        #     post_JSON_API(i)

        pool = ThreadPool(10)
        pool.map(post_JSON_API, dictstr['searchResult']['item'])

        if page_num <= dictstr['paginationOutput']['totalPages']:
            page_num = page_num + 1
        else:
            page_num = 0
        return page_num
    except Exception as e:
        print e
        if try_count <= 3:
            time.sleep(10)
            try_count += 1
            call_Ebay_API(page_num, try_count)
        else:
            raise ValueError(
                "No luck. Tried connecting 3 times and it still didn't work")
Exemple #21
0
def find_it(search):
    api = Connection(config_file='ebay.yaml', debug=DEBUG, siteid="EBAY-US")
    response = api.execute('findItemsByKeywords', search)
    if response.reply.paginationOutput.totalEntries != "0":
        for item in response.reply.searchResult.item:
            print("Title: %s, Price: %s" %
                  (item.title, item.sellingStatus.currentPrice.value))
Exemple #22
0
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())
Exemple #23
0
def find_items_on_ebay():
    api = Connection(appid='Balasubr-hacktech-PRD-916e5579d-aa3f3d9b',
                     config_file=None)
    n_items = int(f_request.args.get('n_items'))
    response = api.execute(
        'findItemsAdvanced', {
            'keywords': f_request.args.get('item'),
            'outputSelector': 'SellerInfo',
            'itemFilter': [{
                'name': 'TopRatedSellerOnly',
                'value': 'true'
            }]
        })
    #response = api.execute('GetCharities', {'Query': 'food'})
    assert (response.reply.ack == 'Success')
    assert (type(response.reply.timestamp) == datetime.datetime)
    assert (type(response.reply.searchResult.item) == list)

    item = response.reply.searchResult.item[0]
    assert (type(item.listingInfo.endTime) == datetime.datetime)
    assert (type(response.dict()) == dict)
    result = response.dict()['searchResult']['item'][:10]
    result = sorted(response.dict()['searchResult']['item'][:n_items],
                    key=lambda x: add_shipping_cost(x))
    # print(result)
    return jsonify(result)
 def __init__(self, api_key, keyword):
     self.api_key, self.keyword = api_key, keyword
     # defin which site we wish to connect to and feed in our api-key
     self.api = Connection(siteid='EBAY-US',
                           appid=self.api_key,
                           config_file=None)
     # create a live db cursor
     self.cursor = database_connection()
     # establish lists for appending data to
     self.active_product_ids = []
     self.active_product_nick = []
     self.active_product_titles = []
     self.active_product_prices = []
     self.active_product_cat_names = []
     self.active_product_cat_ids = []
     self.active_product_img_thumb = []
     self.active_product_img_url = []
     self.active_product_lst_type = []
     self.active_product_con = []
     self.active_product_loc = []
     self.active_product_start = []
     self.active_product_end = []
     self.active_product_watch_count = []
     self.active_product_depth = []
     self.depthCountStorage = []
     # outline our search body paramaters
     self.search_body_pages = {
         'keywords':
         keyword,
         'itemFilter': [
             # US only sellers -- can also limit by feedback score, business type, top-rated status, charity, etc.
             {
                 'name': 'MinPrice',
                 'value': '1',
                 'paramName': 'Currency',
                 'paramValue': 'USD'
             },
             {
                 'name': 'MaxPrice',
                 'value': '99999999',
                 'paramName': 'Currency',
                 'paramValue': 'USD'
             },
             # pre-filter to only actionable items (non-bids, etc.)
             {
                 'name': 'ListingType',
                 'value':
                 ['FixedPrice', 'StoreInventory', 'AuctionWithBIN']
             },
         ],
         'paginationInput': {
             'entriesPerPage': '100',
             # always 1, as we want to pull the maximum number of pages given a maximum of 100 results per page
             'pageNumber': '1'
         },
         # can filter this to multiple different options as well (Best Offer, Most Watched, etc.)
         'sortOrder':
         'PricePlusShippingLowest'
     }
def findItemsAdvanced(keywords):
    api = Finding(appid=myAppId, config_file=None)
    response = api.execute(
        'findItemsAdvanced', {
            'keywords': keywords,
            'categoryId': category,
            'sortOrder': 'PricePlusShippingLowest'
        })
    return response.dict()
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
Exemple #27
0
def commence_search(query):

    try:
        search_term = query
        api = Connection(appid=APP_ID, config_file=None)
        response = api.execute('findItemsByKeywords',
                               {'keywords': search_term})

        assert (response.reply.ack == 'Success')
        assert (type(response.reply.timestamp) == datetime.datetime)
        assert (type(response.reply.searchResult.item) == list)
        item = response.reply.searchResult.item

        search_results = response.dict()

        item = response.reply.searchResult.item[0]
        assert (type(item.listingInfo.endTime) == datetime.datetime)
        assert (type(response.dict()) == dict)
        #print (len(k['searchResult']['item']))

        #print (search_results['searchResult']['item'][0]['itemId'])
        #print (search_results['searchResult']['item'][1]['itemId'])

        item_list = [0] * len(search_results['searchResult']['item'])

        index = 0
        for listing in search_results['searchResult']['item']:

            listing = {
                'id':
                listing['itemId'],
                'title':
                listing['title'],
                'currency':
                listing['sellingStatus']['convertedCurrentPrice']
                ['_currencyId'],
                'price':
                listing['sellingStatus']['convertedCurrentPrice']['value'],
                'start':
                listing['listingInfo']['startTime'],
                'end':
                listing['listingInfo']['endTime'],
                'offerEnabled':
                listing['listingInfo']['bestOfferEnabled'],
                'buyItNowAvailable':
                listing['listingInfo']['buyItNowAvailable'],
                'state':
                listing['sellingStatus']['sellingState']
            }
            item_list[index] = listing
            index += 1
        return item_list

    except ConnectionError as e:

        print(e)
        print(e.response.dict())
def find_cards():
    """
    List a large number of professionally-graded cards from Ebay.

    Parameters:
    -------
    None

    Returns:
    --------
    None

    Populates the data/page_jsons directory with 100 pages (10,000 total cards)
    for each of the 10 PSA grades. Each page is represented as a pickled JSON object,
    example psa_grade_1_page_1.pkl.

    These pages should then be used to acquire the images associated with each card, as well
    as to provide a unique identifier for each image and a label. 

    Labels are acquired by searching for key terms, e.g. "PSA 9" returns cards graded 9/10 by experts
    """

    # Connect to Ebay API. TODO: add your own API keys.
    client_id = "" # TODO add your own API key.
    dev_id = "" # TODO add your own API key.
    client_secret = "" # TODO add your own API key
    api = Connection(appid=client_id, config_file=None)

    # Downlaod Pages of Ebay API data for each grade.
    grades = range(1, 11) # By default, get data for grades 1, 2, .... 10. 
    for grade in grades:
        for page_num in range(1, 100):

            # get data.
            # note: by default we search for baseball cards only, but this can be expanded, 
            # try e.g. "basketball cards", etc.
            # note that some items do not have large enough images available ("PictureURLLarge") and are ignored.
            params = {
             "categoryName": "Baseball Cards",
             "keywords" : "psa {}".format(grade),
             "paginationInput" : 
                    {
                        "entriesPerPage" : 100, # max 100.
                        "pageNumber" : page_num 
                    },
             "outputSelector" : "PictureURLLarge" # important: if not selected, returned images are too small. 
             }
            response = api.execute("findItemsAdvanced", params)
            j = response.json()

            # save
            of_p = "psa_grade_{}_page_{}.pkl".format(grade, page_num)
            of_p = os.path.join("page_jsons", of_p)
            print(of_p)
            with open(of_p, "wb") as of:
                pickle.dump(j, of)
Exemple #29
0
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())
Exemple #30
0
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)