예제 #1
0
def getCurrentPoints(keywords):
    api = Finding(siteid='EBAY-US', appid="JennyHun-7ae2-4c50-abd7-3c1af9cedea5")
    api.execute('findItemsAdvanced', {
        'keywords': 'willow tree shepherd',
        #'categoryId' : ['177', '111422'],
        'itemFilter': [
            {'name': 'Condition', 'value': 'Used'},
            #{'name': 'MinPrice', 'value': '10', 'paramName': 'Currency', 'paramValue': 'USD'},
            #{'name': 'MaxPrice', 'value': '30', 'paramName': 'Currency', 'paramValue': 'USD'}
        ],
        'paginationInput': {
            'entriesPerPage': '3000',
            'pageNumber': '1' 	 
        },
        'sortOrder': 'CurrentPriceHighest',
        #'outputSelector': 'pictureURLLarge'
    })
    dictstr = api.response.dict()
    #print dictstr
    Cprice = []
    Ctime = []
    for item in dictstr['searchResult']['item']:
        print "ItemID: %s" % item['itemId']
        print "Title: %s" % item['title']
        print "URL: %s" % item['galleryURL']
        print "StartTime: %s" % item['listingInfo']['startTime']
        print "endTime: %s" % item['listingInfo']['endTime']
        print "AskingPrice: %s\n" % item['sellingStatus']['currentPrice']['value']
        Cprice.append(float(item['sellingStatus']['currentPrice']['value']))
        datetime = item['listingInfo']['startTime'].split("T")
        Ctime.append(parser.parse(datetime[0]))
    print len(dictstr['searchResult']['item'])
    return (Cprice, Ctime)
예제 #2
0
def getHistoricalPoints(keywords):
    api = Finding(siteid='EBAY-US', appid="JennyHun-7ae2-4c50-abd7-3c1af9cedea5")
    api.execute('findCompletedItems', {
        'keywords': 'Willow Tree shepherd',
        #'categoryId' : ['177', '111422'],
        'itemFilter': [
            {'name': 'Condition', 'value': 'Used'},
            {'name': 'MinPrice', 'value': '0', 'paramName': 'Currency', 'paramValue': 'USD'},
            {'name': 'MaxPrice', 'value': '3000', 'paramName': 'Currency', 'paramValue': 'USD'}
        ],
        'paginationInput': {
            'entriesPerPage': '2000',
            'pageNumber': '1' 	 
        },
        'sortOrder': 'CurrentPriceHighest',
    })
    dictstr = api.response.dict()
    Hprice = []
    Htime = []    
    for item in dictstr['searchResult']['item']:
        print "ItemID: %s" % item['itemId']
        print "Title: %s" % item['title']
        print "CategoryID: %s" % item['primaryCategory']['categoryId']
        #print "URL: %s" % item['galleryURL']
        print "StartTime: %s" % item['listingInfo']['startTime']
        print "endTime: %s" % item['listingInfo']['endTime']
        print "SoldPrice: %s\n" % item['sellingStatus']['currentPrice']['value']
        Hprice.append(float(item['sellingStatus']['currentPrice']['value']))
        datetime = item['listingInfo']['startTime'].split("T")
        Htime.append(parser.parse(datetime[0]))        
    print len(dictstr['searchResult']['item'])
    return (Hprice, Htime)
    print Hprice    
예제 #3
0
파일: ebay.py 프로젝트: moudlajs/auct-web
    def get_body(self):
        api = Finding(config_file="ebay.yaml")
        excl_cat = self.get_excl_categories()

        # had to change utils.py (from ebaysdk) - method parse_yaml
        # code checks whether line starts with "-", then stops parsing process
        
        try:
            keywords = self.get_keywords()
            cat = self.get_categories()
        except ValueError as err:
            self.print_log(err)
            return None

        try:
            response = api.execute('findItemsAdvanced',
                                   {'keywords': keywords,
                                    'categoryId': cat,
                                    'excludeCategory': excl_cat,
                                    #'itemFilter': [
                                    #    {'name': 'AvailableTo',
                                    #     'value': 'CZ'}]
                                    })
        except ConnectionError as err:
            self.print_log(err)
            return None                     
        return response
예제 #4
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())
예제 #5
0
파일: ebay.py 프로젝트: chrichaa/ls-project
def fetch_results(item,min_price,max_price):
    try:
        api = Finding(appid="Jeremiah-c9e4-41cd-93a3-db5086f58faf")
        response = api.execute('findItemsAdvanced', {'keywords': item, 'sortOrder': 'StartTimeNewest', 'itemFilter': {'name' : 'MinPrice' , 'value' : min_price, 'paramName' : 'Currency', 'paramValue' :'USD'}, 'itemFilter': {'name' : 'MaxPrice' , 'value' : max_price, 'paramName' : 'Currency', 'paramValue' :'USD'}})

        dictionary = response.dict()

        if 'item' in dictionary['searchResult']:
            count = 0
            temp_dictionary = {}
            
            for key in dictionary['searchResult']['item']:
                    item_id = key['itemId']
                    title   = key['title']
                    url     = key['viewItemURL']
                    price   = key['sellingStatus']['currentPrice']['value']
                    time    = dateutil.parser.parse(key['listingInfo']['startTime'])
                    
                    if not price:
                        price = "0"

                    temp_dictionary[str(count)] = {'title': title.strip(), 'url': url.strip(), 'price' : price.strip(), 'time' : time, 'key': item_id.strip()};
                    count = count + 1
                   
            #print json.dumps(temp_dictionary, sort_keys=True, indent=4, separators=(',', ': '))
        
            send_to_database(item,min_price,max_price,temp_dictionary,count)
        else:
            count = 0

        return count
    except ConnectionError as e:
        print(e)
        print(e.response.dict())
        return 0 
예제 #6
0
def initial_execute(item_name):
    global category_List
    global category_Lookup

    pastDate = date.today() - timedelta(days=90)
    datestr = pastDate.strftime('%Y-%m-%d') + 'T00:00:00.000Z'
    try:
        api = Finding(appid = "TaylorMo-1104-4ca1-bc59-34b44b585cf0", config_file = None)
        api_request = {
            'keywords': item_name,
            'itemFilter': [
                {'name': 'SoldItemsOnly', 'value': True},
                {'name': 'LocatedIn', 'value': 'US'},
                {'name': 'EndTimeFrom', 'value': datestr}
            ]
        }
        response = api.execute('findCompletedItems', api_request)
    except ConnectionError as e:
        print(e)

    results = response.dict().get('searchResult')
    itemList = results.get('item')
    catList = []
    if (itemList != None):
        for items in itemList:
            catList.append(items.get('primaryCategory').get('categoryName'))
            category_Lookup[items.get('primaryCategory').get('categoryName')] \
                = items.get('primaryCategory').get('categoryId')

    catDict = Counter(catList)
    category_List = sorted(catDict, key = catDict.__getitem__)
    category_List.reverse()
def search_ebay(APP_ID, craigslist_item):  
	
	api = Finding(appid=APP_ID, config_file=None)
	response = api.execute('findItemsAdvanced', {'keywords': craigslist_item})
	dict = response.dict()['searchResult']['item']
	
	return dict
예제 #8
0
def ebay_api_data(input_list, time_string, real = 1):
    if (real == 1):
        f = open('./data/' + time_string[:-6] + 'ebay.txt', 'w+')
    else:
        f = open('./data/' + time_string[:-6] + 'all_ebay_gc', 'w+')
    res = dict()
    size = len(input_list)
    try:
        api = Finding(appid="YuHUANG-insightd-PRD-04d8cb02c-4739185d")
        for i in xrange(0, size):
            if (i == 50):
                continue
            cur_list = input_list[i]
            if (cur_list[0] != 'soak-&-sleep'):
                response = api.execute('findItemsAdvanced', {'keywords': cur_list[0] + ' Gift Card'})
                json_data1 = json.dumps(response.dict(), ensure_ascii=True)
                json_data = json.loads(json_data1)
                if (json_data['searchResult']['_count'] == '0'):
                    continue
                json_array = json_data['searchResult']['item']
                array_len = len(json_array)
                for j in xrange(0, array_len):
                    cur_obj = json_array[j]
                    list_info = cur_obj['listingInfo']
                    selling_status = cur_obj['sellingStatus']
                    half1 = time_string[:-6] + ',' + cur_obj['itemId'].replace(',','') + ',' + cur_obj['title'].replace(',','') + ',' + cur_obj['viewItemURL'] + ',' + list_info['buyItNowAvailable'] + ',' + list_info['startTime'] + ','
                    half2 =  list_info['endTime'] + ',' + selling_status['currentPrice']['value'] + ',' + selling_status['currentPrice']['value'] + ',' + cur_list[0] + ',' + cur_obj['autoPay'] + '\n'
                    f.write(half1.encode('utf-8') + half2.encode('utf-8'))
        f.close()
    except ConnectionError as e:
        print(e)
        print(e.response.dict())
예제 #9
0
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()

    print items
    for line in items:
        print line
예제 #10
0
class EbayFetcher():

    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
예제 #11
0
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
예제 #12
0
def findItemsAdvanced(keywords):
    api = Finding(appid=myAppId, config_file=None)
    response = api.execute(
        'findItemsAdvanced', {
            'keywords': keywords,
            'categoryId': category,
            'sortOrder': 'PricePlusShippingLowest'
        })
    return response.dict()
예제 #13
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())
예제 #14
0
def ebay_search(search, max_price, min_price, condition, num_to_print,
                located_in):
    try:
        ebay_client = Finding(siteid='EBAY-US', appid=app_id, config_file=None)
        ebay_client.execute(
            'findItemsAdvanced', {
                'keywords':
                search,
                'categoryId':
                176985,
                'itemFilter': [{
                    'name': 'MaxPrice',
                    'value': max_price,
                    'paramName': 'Currency',
                    'paramValue': 'USD'
                }, {
                    'name': 'MinPrice',
                    'value': min_price,
                    'paramName': 'Currency',
                    'paramValue': 'USD'
                }, {
                    'name': 'AuctionWithBIN'
                }, {
                    'name': 'Condition',
                    'value': condition
                }, {
                    'name': 'HideDuplicateItems',
                    'value': 'true'
                }, {
                    'name': 'LocatedIn',
                    'value': located_in
                }],
                'paginationInput': {
                    'entriesPerPage': num_to_print,
                    'pageNumber': '1'
                },
                'sortOrder':
                'CurrentPriceHighest'
            })
    except ConnectionError as e:
        print(e)

    search_results = ebay_client.response.dict()
    return search_results
예제 #15
0
파일: __init__.py 프로젝트: soasada/Glibert
class EbayAPICall():
    """Wrapper class for the Finding API calls

    API reference: (http://developer.ebay.com/devzone/finding/)

    NOTE: Before use remember to provide an appID in the `ebay.yaml` file!

    """

    def __init__(self, **kwargs):
        """Constructor for the class:

        Parameters:
            Same as Finding constructor (https://github.com/timotheus/ebaysdk-python/wiki/Finding-API-Class)

        """

        self.api = Finding(**kwargs)


    def make_call(self, api_request):
        """Make the API call with the given parameters.

        Parameters:
            api-request     -- dict with the API call parameters (http://developer.ebay.com/devzone/finding/CallRef/types/AspectFilter.html)
        Return:
            Dict of the API response

        """

        try:
            response = self.api.execute('findItemsAdvanced', api_request)

        except ConnectionError as e:
            code = e.response.dict()['errorMessage']['error']['errorId']
            if code == '11002':
                print("---> Maybe you've forgotten to put a valid `appid` inside `ebay.yaml`.")
            else:
                print(e)

        return response.dict()

    def to_file(self, data, out_filename='ebay_items.json'):
        """Writes data to a file.

        Parameters:
            data            -- actual data to write (usually the JSON response)
            out_filename    -- output filename (default 'ebay_items.json')

        """

        if data:
            with open(out_filename, 'w') as outfile:
                json.dump(data, outfile)
        else:
            print("No data given")
예제 #16
0
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)
예제 #17
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())
예제 #18
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)
예제 #19
0
def itemFinder(search_item,inten):
    items = []
    intens = int(inten)
    try:
        api = Finding(appid="ScottRus-bf7d-437a-a830-3735324dd553",config_file=None,debug=True)
        for page_num in range(intens):
            # TODO: Change back to range later
            response = api.execute('findCompletedItems', {'keywords': search_item,'paginationInput': {'entriesPerPage': 100, 'pageNumber':page_num}})
            response_dict = response.dict()
            if response_dict['ack'] == 'Failure':
                continue
            else:
                items.append(response.dict())
    except:
        error_logging("ConEng", "Failed")

    for s_item in items:
        # Assign searchResult value to variable
        search_result = s_item['searchResult']
        # Assign item value to item_array
        item_array = search_result['item']

        count = 0
        try:
            for item in item_array:
                count += 1
                # Get selling status
                selling_status_price = item['sellingStatus']
                selling_status_price = item['sellingStatus']
                #Get current price
                current_price = selling_status_price['currentPrice']
                value = float(current_price['value'])

                # Store price in price_array
                price_array.append(value)

                # Get the listingInfo
                listing_info = item['listingInfo']
                # Get endTime
                end_time = listing_info['endTime']
                sliced_date = end_time[:10]
                a = dt.strptime(sliced_date, '%Y-%m-%d').date()
                # Start date
                star_date = datetime.date(2015,1,1)
                delta = a - star_date
                # Get date number relative to the year
                int_delta = int(delta.days)
                # Store Date in date array
                date_array.append(int_delta)
                # Y X pair
                point_tuple = (value,int_delta)
                point_array.append(point_tuple)
        except:
            error_logging("ConEng", "Failed")
예제 #20
0
def findCurrentItem(name):
  api = Finding(appid='VarunRam-29e8-46c1-87ef-dbcf272585f7', 
                config_file =None)
  api_request = {
      'keywords': name,
      'sortOrder': 'CurrentPriceHighest',
  }
  response = api.execute('findCompletedItems', api_request)

  assert(response.reply.ack == 'Success')
  return response.dict()
예제 #21
0
def find_item_advanced(page_num):
    api = Connection(siteid='EBAY-US',
                     appid='Enter your Key here',
                     config_file=None)

    #Following are product and details you want to get from API.
    api.execute(
        'findItemsAdvanced', {
            'keywords': 'iphone xr',
            'itemFilter': [{
                'name': 'Condition',
                'value': 'Used'
            }],
            'paginationInput': {
                'entriesPerPage': '25',
                'pageNumber': page_num
            }
        })

    dictstr = api.response.dict()
    return dictstr
예제 #22
0
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
예제 #23
0
def api_all():
    error = False

    response = {'result': 'null'}
    try:
        if 'search' in request.args:
            search = request.args['search']
        else:
            response['error_2'] = "Error: No search field provided. Please search for products."
        link = "https://api.bestbuy.com/v1/products(search={})?format=json&show=name,salePrice,addToCartUrl,largeImage&apiKey=N0ReEPP28MPw3Gd2xSIAQ5dM".format(search)
        data = json.loads(urllib.request.urlopen(link).read().decode()) #Retrieve data from bestbuyAPI
        products = data['products']
        for item in products: #Rename url and include retailer name to the items
            item['url']  = item.pop('addToCartUrl')
            item['retailer'] = 'BestBuy'
        
        #eBay Code 
        api = Connection(config_file='ebay.yaml') #Connect to the API using authentication file
        res = api.execute('findItemsAdvanced', {'keywords': search}) #Retrieve data using eBay developer API

        items = res.reply.searchResult.item[:10] #Only use the first 10 results
        ebay_products = []
        
        for item in items:
            ebay_product = {}
            name = item.get('title') #Retrieve name, price, image, link to purchase product

            sellingStatus = item.get('sellingStatus')
            currentPrice = sellingStatus.get('currentPrice')
            salePrice = float(currentPrice.get('value'))
            
            largeImage = item.get('galleryURL')
            url = item.get('viewItemURL')
            #Format dictionary to match the categories that were used for the Best Buy products
            ebay_product['name'] = name 
            ebay_product['retailer'] = 'eBay'
            ebay_product['salePrice'] =salePrice 
            ebay_product['largeImage'] = largeImage 
            ebay_product['url'] = url
            
            ebay_products.append(ebay_product)
            
        products.extend(ebay_products) #Extend the dictionary to include the ebay products
        products = sorted(products, key = lambda i: i['salePrice']) #Sort by price
        response['result'] = products
    except Exception as err:
        response['error'] = str(err)
        error = True
    
    return sendResponse(response, error)
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
예제 #25
0
def eBay_scratch():
    import datetime
    from ebaysdk.finding import Connection

    api = Connection(appid='SubhashB-f237-485e-9a38-318aa7e72eee')
    response = api.execute('findItemsAdvanced', {'keywords': 'legos'})

    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)
예제 #26
0
 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
예제 #27
0
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)
예제 #28
0
def search_ebay():
	searchword = request.args.get('q', '')
	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)
		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())
예제 #29
0
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", [])
예제 #30
0
    def get_response(self):
        """Searches eBay according to the settings.
        If ´ebay_module´ = False, returns None.

        Returns:
            ResponseObject

        Raises:
            ConnectionError: If connection is not available for
            any reason, returns None


        """
        # api = Finding(config_file="../ebay.yaml")

        if os.path.exists(self.appid):
            api = Finding(config_file=self.appid)
        elif not self.appid:
            api = Finding(appid=self.appid, config_file=None)
        elif os.environ.get("APPID_KEY", ""):
            api = Finding(appid=os.environ["APPID_KEY"], config_file=None)
        else:
            raise("eBay API key improperly configured")

        excl_cat = self._get_excl_categories()

        try:
            keywords = self.get_keywords()
            cat = self._get_categories()
        except ValueError as err:
            self.print_log(err)
            return None
        try:
            # TODO: extend search parameters
            response = api.execute('findItemsAdvanced',
                                   {'keywords': keywords,
                                    'categoryId': cat,
                                    'excludeCategory': excl_cat,
                                    # 'itemFilter': [
                                    #    {'name': 'AvailableTo',
                                    #     'value': 'CZ'}]
                                    })
        except ConnectionError as err:
            self.print_log(err)
            return None
        except requests.exceptions.ConnectionError as err:
            self.print_log(err)
            return None
        return response
예제 #31
0
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())
예제 #32
0
    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
예제 #33
0
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)
예제 #34
0
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
예제 #35
0
 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()
예제 #36
0
파일: api.py 프로젝트: mlosch/py-DeBayP
    def test(self):
        try:
            api = Connection(config_file='../ebayconf.yaml')
            response = api.execute('findItemsAdvanced', {'keywords': 'legos'})

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

            item = response.reply.searchResult.item[0]
            self.assertTrue(type(item.listingInfo.endTime) == datetime.datetime)
            self.assertTrue(type(response.dict()) == dict)

        except ConnectionError as e:
            print(e)
            print(e.response.dict())
예제 #37
0
파일: ebay.py 프로젝트: tiagosvf/ethrift
    def get_items():
        """Task ran by Getter threads to get new items listed from the searches
        in the queue

        Gets next search from the queue and formats it's filters to then create 
        a findItemsAdvanced request object. New items are then sourced from the
        reponse."""

        while True:
            try:
                self = queue.pop(0)

                temp_filters = self.get_filters()

                while temp_filters:
                    try:
                        filters, temp_filters = temp_filters.get_for_request()

                        api = Finding(domain=settings.get("domain"),
                                      appid=settings.get("appid"),
                                      version=settings.get("version"),
                                      config_file=None,
                                      site_id=self.ebay_site)

                        api_request = {'keywords': f'{self.keywords}',
                                       'itemFilter': filters,
                                       'sortOrder': 'StartTimeNewest'}

                        response = api.execute(
                            'findItemsAdvanced', api_request)

                        # # FIXME: Uncomment for debug only
                        # print(f"{response.headers}  :  {response.content}")

                        Item.items_from_response(self, response)
                    except ConnectionError:
                        pass
                    except AttributeError as e:
                        print(f"Exception in get_items: {e}")
                        pass
                    except Exception as e:  # idc just stop breaking
                        print(f"Exception in get_items: {e}")
                        pass

            except IndexError:
                time.sleep(0.01)
                continue
예제 #38
0
def get_list_of_items(request, params=None):
    try:
        api = Connection()
        response = api.execute(request, params)

        assert(response.reply.ack == 'Success')
        assert(type(response.reply.timestamp) == datetime.datetime)
        # assert(type(response.reply.searchResult.item) == list)
#todo if empty list
        # item = response.reply.searchResult.item[0]
        # assert(type(item.listingInfo.endTime) == datetime.datetime)
        # assert(type(response.dict()) == dict)
        return response.dict()

    except ConnectionError as e:
        print(e)
        print(e.response.dict())
예제 #39
0
def ebayapiexample():
    '''
    Example of using an ebay API
    Returns information about one found product placed on ebay
    ('Stephen King The Shining' - as an example)
    ebay.json - api configuration
    '''
    try:
        api = Finding(config_file='ebay.json', appid='*')

        request = {'keywords': 'Stephen King The Shining'}
        response = api.execute('findItemsAdvanced', request)

        return response.dict()['searchResult']['item'][0]['sellingStatus']

    except ConnectionError as err:
        return err.response.dict()
예제 #40
0
def deals(keyword):
    try:
        api = Connection(appid=secrets.ebay, config_file=None)
        response = api.execute('findItemsAdvanced', {'keywords': keyword})

        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)
        return response.dict()

    except ConnectionError as e:
        print(e)
        print(e.response.dict())
예제 #41
0
def ebayScrape(keywords):
    try:
        api = Finding(siteid='EBAY-GB',
                      appid='EddWilli-classicc-PRD-6246ab0a7-20318a15',
                      config_file=None)
        api_request = {
            'keywords':
            '',
            'categoryId':
            '9801',
            'itemFilter': [{
                'name': 'Condition',
                'value': 'Used'
            }, {
                'name': 'Model Year',
                'value': ''
            }],
            'sortOrder':
            'CountryDescending',
        }

        api_request['keywords'] = keywords
        api_request[
            'itemFilter'] = "{'name': 'Condition', 'value' : 'Used'}, { 'name' : 'ListingType', 'Value' : 'Classified' }"

        response = api.execute('findItemsAdvanced', api_request)

        # print type(response.reply.paginationOutput.totalEntries)

        average = 0
        amount = 0

        if int(response.reply.paginationOutput.totalEntries) > 0:
            # print dir(response.reply.searchResult.item)
            for i in response.reply.searchResult.item:
                # print "Title: %s // Price: %s" % (i.title, i.sellingStatus.currentPrice.value)
                average += float(i.sellingStatus.currentPrice.value)
                amount += 1
                return average / amount
        else:
            print "Nothing found on eBay"

    except ConnectionError as e:
        print(e)
        print(e.response.dict())
예제 #42
0
def search(opts, keywords, category_id, n_listings=100):
    print("KEYWORDS", keywords)
    try:
        api = Connection(config_file=opts['config_fpath'], appid=opts['appid'])
        response = api.execute('findItemsAdvanced', {'keywords': keywords})

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

        items = response.reply.searchResult.item[:n_listings]
        assert (type(response.dict()) == dict)
        return response.dict()

    except ConnectionError as e:
        print(e)
        print(e.response.dict())
예제 #43
0
def get_history(request):
    if request.method == 'POST':
        data = request.POST.get('data')
        data = json.loads(data)
        if 'search' in data:
            keywords = data['search']
            try:
                api = Connection(appid='JeffreyC-Streetwe-PRD-f2f871c7c-922e659d', config_file=None)
                response = api.execute('findCompletedItems', {'keywords': keywords})
                return HttpResponse(response.json())

            except ConnectionError as e:
                return HttpResponse("Connection error.")

        else:
            return HttpResponse("No search.")
    else:
        return HttpResponse("Must be a POST request.")
예제 #44
0
def get_ebay_page(query, page=1, entries=200, search_type='findItemsAdvanced'):
    try:
        api = Finding(appid=creds['ebay']['appID'], config_file=None)
        response = api.execute(
            search_type, {
                'keywords': query,
                'outputSelector': ['PictureURL', 'PictureURLSuperSize'],
                'paginationInput': {
                    'entriesPerPage': str(entries),
                    'pageNumber': str(page)
                },
            })

        return response.dict()

    except ConnectionError as e:
        print(e)
        return e.response.dict()
예제 #45
0
def find_it(search, existing_ids):
    api = Connection(config_file='ebay.yaml', debug=DEBUG, siteid="EBAY-US")
    response = api.execute('findCompletedItems', search)
    result_list = []
    if response.reply.paginationOutput.totalEntries != "0":
        for item in response.reply.searchResult.item:
            if str(item.itemId) not in existing_ids:
                result_list.append({
                    "item_id":
                    item.itemId,
                    "title":
                    item.title,
                    "end_date":
                    item.listingInfo.endTime,
                    "price":
                    item.sellingStatus.currentPrice.value
                })
    return result_list
예제 #46
0
def getItem(num):
    try:
        api = Connection(domain='svcs.sandbox.ebay.com', appid='TristanW-PetContr-SBX-3577624e3-6f8339d7', config_file=None)
        response = api.execute('findItemsAdvanced', {'keywords': 'Dog 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[num]

        assert(type(item.listingInfo.endTime) == datetime.datetime)
        assert(type(response.dict()) == dict)

    except ConnectionError as e:
        print(e)
        print(e.response.dict())
    return item;
예제 #47
0
class Ebay():
    def __init__(self):
        self.api = Connection(config_file='ebay.yaml', siteid='EBAY-US')

    def search(self, keywords):
        request = {
            'keywords': keywords,
            'itemFilter': [{
                'name': 'LocatedIn',
                'value': 'US'
            }],
            'paginationInput': {
                'entriesPerPage': 100,
                'pageNumber': 1
            },
            'sortOrder': 'BestMatch'
        }
        response = self.api.execute('findItemsByKeywords', request).dict()

        items = []
        for listing in response['searchResult']['item']:
            item = {}

            item['listingType'] = listing['listingInfo']['listingType']
            item['currentPrice'] = listing['sellingStatus']['currentPrice'][
                'value']

            if listing['shippingInfo']['shippingType'] == 'Flat':
                shipping_price = float(
                    listing['shippingInfo']['shippingServiceCost']['value'])
                item['totalPrice'] = float(
                    item['currentPrice']) + shipping_price
            else:
                item['totalPrice'] = item['currentPrice']

            items.append(item)

        return pd.DataFrame(items).apply(pd.to_numeric, errors='ignore')

    def mean_buy_price(self, keywords):
        items = self.search(keywords)
        items = items[(items.listingType == 'StoreInventory') |
                      (items.listingType == 'FixedPrice')]
        return items.totalPrice.mean()
예제 #48
0
def findItem(name, timeStart, timeEnd):
  api = Finding(appid='VarunRam-29e8-46c1-87ef-dbcf272585f7', 
                config_file =None)
  api_request = {
      'keywords': name,
      'sortOrder': 'EndTimeSoonest',
      'itemFilter': {
        'name': 'SoldItemsOnly',
        'value': 'true',
        'name':'EndTimeFrom',
        'value':timeStart,
        'name':'EndTimeTo',
        'value':timeEnd
      }
  }
  response = api.execute('findCompletedItems', api_request)

  assert(response.reply.ack == 'Success')
  return response.dict()
예제 #49
0
    def get(self):
        api = Finding(config_file="ebay.yaml")
        user_param = parse_params_api_search()
        custom_search = gen_custom_search(user_param)
        response = api.execute('findItemsAdvanced', custom_search)
        ebay_response = response.dict()

        if "Failure" in ebay_response['ack']:
            return custom_error(400, "Not a valid search.",
                                "Try a different search ")
        # sandbox had some issues returning a response with no entries
        ebay_response, count = check_if_resp_empty(ebay_response)

        if isinstance(ebay_response, Response):
            return ebay_response
        else:
            return generate_json_for_gui(
                ebay_response, count,
                user_param)  # custom_search does have the dict
def get_categories(appid, keyword):
    try:
        api = Connection(appid=appid, config_file=None)
        response = api.execute('findItemsAdvanced', {'keywords': keyword}).json()
        
        item_dict = json.loads(response)
        items = item_dict['searchResult']['item']
        categories = {}
        for item in items:
            c_id = item['primaryCategory']['categoryId']
            c_name = item['primaryCategory']['categoryName']
            categories.update({c_id: c_name})
               
        print len(categories)
        for k,v in categories.items():
            print k, v
    
    except ConnectionError as e:
        print(e)
        print(e.response.dict())
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
예제 #52
0
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())
예제 #53
0
import datetime

try:
    from ebaysdk.finding import Connection as Finding
except:
    import pip
    pip.main(['install', '--user', 'ebaysdk'])
    from ebaysdk.finding import Connection


try:
    api = Finding(appid=appid, config_file=None)

    response = api.execute('findItemsByProduct', {'productId.type':'ReferenceID', 'productID.value':'311341714658' })
    print(response.dict())
except ConnectionError as e:
    print(e)
    print(e.response.dict())

예제 #54
0
파일: ebay.py 프로젝트: lehrian/eBuyBot
class ebay:
	def __init__(self):
		self.finding = Finding()
		self.categories = self.getCategories()

	def getItems(self, minPrice = "0.0", maxPrice = "2.0", listingType = "FixedPrice",
		freeShippingOnly = "true", keywords = "(or,and,of,is,i,if,at,where,when,you,why,how,new,used)",
		sortOrder = "StartTimeNewest", categoryID = "-1", pageNumber = "1"):
		request = {
			"itemFilter": [
				{"name": "MinPrice", "value": minPrice},
				{"name": "MaxPrice", "value": maxPrice},
				{"name": "ListingType", "value": listingType},
				{"name": "FreeShippingOnly", "value": freeShippingOnly}
			],
			"keywords": keywords,
			"sortOrder": sortOrder,
			#"descriptionSearch": "true", #Doesn't work for some reason?
			"CategoryID": categoryID,
			"pageNumber": pageNumber
		}
		try:
			response = self.finding.execute("findItemsAdvanced", request).dict()
			return response
		except ConnectionError as e:
			print(e)
			print(e.response.dict())
			return {}

	def buyItem(self):
		pass

	def getCategories(self):
		catList = Shopping().execute("GetCategoryInfo", {"CategoryID": "-1", "IncludeSelector": "ChildCategories"}).dict()["CategoryArray"]["Category"]
		for cat in catList: #meow
			if cat["CategoryID"] != "-1": #perhaps not, would give randomly selecting from all categories
				catList.remove(cat)
		return catList

	def getRandomCategory(self):
		return self.categories[random.randint(0, len(self.categories) - 1)]

	def randomItem(self):
		try:
			randomCategory = self.getRandomCategory()
			response = self.getItems(categoryID = randomCategory)

			count = int(response["searchResult"]["_count"])
			totalCount = int(response["paginationOutput"]["totalEntries"])

			if totalCount >= 10000: #eBay has a dumb 100 page, 100 entries/page limit, so
				totalCount = 999 #a total limit of 10000

			if count < 1:#TODO: error handling
				print("No results :(")
				return

			elif totalCount <= 100:
				print(str(count) + " results from category: " + randomCategory["CategoryName"])
				results = response["searchResult"]["item"]
				print(results[random.randint(0, count - 1)]["viewItemURL"])

			else:
				pageNumber = int(totalCount/100) + 1
				response = self.getItems(categoryID = randomCategory, pageNumber = str(pageNumber))

				results = response["searchResult"]["item"]
				count = int(response["searchResult"]["_count"])

				print(str(totalCount) + " results from category: " + randomCategory["CategoryName"])
				results = response["searchResult"]["item"]
				print(results[random.randint(0, count - 1)]["viewItemURL"])

		except ConnectionError as e:
			print(e)
			print(e.response.dict())
import ebaysdk
from ebaysdk.finding import Connection as Finding
import pylab
#import rpy2
from dateutil import parser

api = Finding(siteid='EBAY-US', appid="JennyHun-7ae2-4c50-abd7-3c1af9cedea5")
api.execute('findCompletedItems', {
    'keywords': 'willow tree shepherd',
    #'categoryId' : ['177', '111422'],
    'itemFilter': [
        {'name': 'Condition', 'value': 'Used'},
        {'name': 'MinPrice', 'value': '0', 'paramName': 'Currency', 'paramValue': 'USD'},
        {'name': 'MaxPrice', 'value': '3000', 'paramName': 'Currency', 'paramValue': 'USD'}
    ],
    'paginationInput': {
        'entriesPerPage': '2000',
        'pageNumber': '1' 	 
    },
    'sortOrder': 'CurrentPriceHighest',
})

dictstr = api.response.dict()
price = []
time = []

for item in dictstr['searchResult']['item']:
    print "ItemID: %s" % item['itemId']
    print "Title: %s" % item['title']
    print "CategoryID: %s" % item['primaryCategory']['categoryId']
    print "URL: %s" % item['galleryURL']
예제 #56
0
파일: ebay.py 프로젝트: steve84/thesis-src
		# initialise eBay Finding API
    api = Finding(appid='INSERT_APP_ID')
    
    ground_truth = list()
    # read the predefined keywords
    with open('keywords.txt') as f:
        content = f.readlines()
        
    for keyword in content:
				# search for a sold auction item which contains the keyword and the payment was done in USD
        api.execute('findCompletedItems', {
            'keywords': keyword,
            'itemFilter': [
                {'name': 'ListingType',
                 'value': 'Auction'},
                {'name': 'Currency',
                 'value': 'USD'},                
                {'name': 'SoldItemsOnly',
                 'value': 'true'},                 
            ],        
            'sortOrder': 'StartTimeNewest',
            })

        response = json.loads(api.response_json())
        items = response['searchResult']['item']
        count = int(response['searchResult']['count']['value'])
        
        for x in range(0,count):
						# get the item information
            item = getItemDetails(int(items[x]['itemId']['value']))
            if item != 'null':
                ground_truth.append(item)
예제 #57
0
def query_category(request, page, category_id):
    #parse query from filter
    query_attrs = {}

    #Condition
    conditions = ['1000', '1500', '1750']

    query_attrs['cond_new'] = request.GET.get('cond_new', '')
    if not query_attrs['cond_new']:
        conditions.remove('1000')

    query_attrs['cond_nwb'] = request.GET.get('cond_nwb', '')
    if not query_attrs['cond_nwb']:
        conditions.remove('1500')

    query_attrs['cond_def'] = request.GET.get('cond_def', '')
    if not query_attrs['cond_def']:
        conditions.remove('1750')

    if conditions == []:
     	conditions = ['1000']

    #Material
    materials = ['Leather', 'Suede', 'Patent Leather', 'Canvas', 'Rubber', 'Snakeskin', 'Synthetic', 'Vegan']

    query_attrs['leather'] = request.GET.get('leather', '')
    if not query_attrs['leather']:
        materials.remove('Leather')

    query_attrs['suede'] = request.GET.get('suede', '')
    if not query_attrs['suede']:
        materials.remove('Suede')

    query_attrs['patent_leather'] = request.GET.get('patent_leather', '')
    if not query_attrs['patent_leather']:
        materials.remove('Patent Leather')

    query_attrs['canvas'] = request.GET.get('canvas', '')
    if not query_attrs['canvas']:
        materials.remove('Canvas')

    query_attrs['rubber'] = request.GET.get('rubber', '')
    if not query_attrs['rubber']:
        materials.remove('Rubber')

    query_attrs['snakeskin'] = request.GET.get('snakeskin', '')
    if not query_attrs['snakeskin']:
        materials.remove('Snakeskin')

    query_attrs['synthetic'] = request.GET.get('synthetic', '')
    if not query_attrs['synthetic']:
        materials.remove('Synthetic')

    query_attrs['vegan'] = request.GET.get('vegan', '')
    if not query_attrs['vegan']:
        materials.remove('Vegan')

    # if materials == []:
    #  	materials = ['Leather']

    #Min and Max Prices
    query_attrs['min-price'] = request.GET.get('min-price', '')
    if not query_attrs['min-price']:
        query_attrs['min-price'] = '0'

    query_attrs['max-price'] = request.GET.get('max-price', '')
    if not query_attrs['max-price']:
        query_attrs['max-price'] = '1000'


    #US Shoes Sizes
    sizes = ['6', '6.5', '7', '7.5', '8', '8.5', '9', '9.5', '10']

    query_attrs['size6'] = request.GET.get('size6', '')
    if not query_attrs['size6']:
        del query_attrs['size6']
        sizes.remove('6')

    query_attrs['size6.5'] = request.GET.get('size6.5', '')
    if not query_attrs['size6.5']:
        del query_attrs['size6.5']
    	sizes.remove('6.5')

    query_attrs['size7'] = request.GET.get('size7', '')
    if not query_attrs['size7']:
        del query_attrs['size7']
    	sizes.remove('7')

    query_attrs['size7.5'] = request.GET.get('size7.5', '')
    if not query_attrs['size7.5']:
        del query_attrs['size7.5']
        sizes.remove('7.5')

    query_attrs['size8'] = request.GET.get('size8', '')
    if not query_attrs['size8']:
        del query_attrs['size8']
        sizes.remove('8')

    query_attrs['size8.5'] = request.GET.get('size8.5', '')
    if not query_attrs['size8.5']:
        del query_attrs['size8.5']
        sizes.remove('8.5')

    query_attrs['size9'] = request.GET.get('size9', '')
    if not query_attrs['size9']:
        del query_attrs['size9']
        sizes.remove('9')

    query_attrs['size9.5'] = request.GET.get('size9.5', '')
    if not query_attrs['size9.5']:
        del query_attrs['size9.5']
        sizes.remove('9.5')

    query_attrs['size10'] = request.GET.get('size10', '')
    if not query_attrs['size10']:
        del query_attrs['size10']
        sizes.remove('10')

    # if sizes == []:
    # 	sizes = ['7']

    #connect to ebay api and search items
    api = Connection(appid='*****')
    response = api.execute('findItemsIneBayStores', {
    'storeName': '*****', 
    'categoryId': category_id,

    'itemFilter': [
    {'name': 'ListingType','value': 'FixedPrice'},
    {'name': 'BIN','value': '1'},
    {'name':'MinPrice', 'value':query_attrs['min-price']},
    {'name':'MaxPrice', 'value':query_attrs['max-price']},
    {'name':'Condition', 'value':conditions},
    ], 

    'aspectFilter': [
    {'aspectName': 'Material', 'aspectValueName':materials},
    {'aspectName': 'US Shoe Size (Women\'s)', 'aspectValueName':sizes},
    ],

    'sortOrder':
    'PricePlusShippingLowest', 

    'paginationInput':
    {'entriesPerPage':'100', 'pageNumber':page}})

    time.sleep(1)
    
    try:
        items = response.reply.searchResult.item

        total_pages = response.reply.paginationOutput.totalPages
        total_entries = response.reply.paginationOutput.totalEntries

        imgs = []
        #price calculations
        for i in items:
            price = float(i.sellingStatus.currentPrice.value)
            price = price + price*0.15
            price = round(price, 2)
            if price < 10:
                price +=5

            elif 10 < price < 20:
                price +=2

            i.sellingStatus.currentPrice.value = str(price)
            i.title = i.title.rsplit(' ', 2)[0] #cutting Blemish blabla
            imgs.append([i.galleryPlusPictureURL, i.title, i.itemId, i.sellingStatus.currentPrice.value, i.condition.conditionDisplayName]) 
        return	{'imgs':imgs, 
        'category':category_id,
        'total_pages':total_pages, 
        'total_entries':total_entries,
        'minprice_selected':query_attrs['min-price'],
        'maxprice_selected':query_attrs['max-price'],}
    except:
    	return 0
예제 #58
0
파일: bkp.py 프로젝트: sbryo/dinero
########################## Connect History DB ########################
client3 = MongoClient('ds019254.mlab.com',19254)
client3.history.authenticate('shakedinero','a57821688')
db_history = client3.history

############## get KEYWORDS from Search DB #################################
cursor = db_search.search.shaked.find()
for document in cursor:
    KEYWORDS=document['search']

########################################################### EBAY ########################################################
ebay_list = []
try:
    api = Connection(appid='Shaked-B-976d-45bc-a23a-71ab251884fb',config_file=None)
#response details:
    response = api.execute('findItemsAdvanced',{'keywords':KEYWORDS})

    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)

    for ITEM in response.reply.searchResult.item:
        try:
            LIST = str(ITEM).split("'value':")
            SHIPPING_PRICE = (LIST[1].split("'"))[1]
            if SHIPPING_PRICE == '0.0':
                SHIPPING_PRICE = 'Free'