def test_alternative_config(self): """ Move configuration file ``config.ini`` to nonstandard location (one level up in directory hierarchy) and try to use the library. """ #Backup the initialization file system("cp " + std_conf + " " + std_conf_back) #Move initialization file to nonstandard location system("mv " + std_conf + " " + alt_conf) #Look where the initialization files really are system(ls_command + std_conf) system(ls_command + std_conf_back) system(ls_command + alt_conf) #Set alternative initialization file set_config_file(set_alt_conf) #Use the library and test if it works result = findItemsByKeywords(keywords=keywords, paginationInput=paginationInput, encoding=encoding) root = etree.fromstring(result) ack = root.find( "{http://www.ebay.com/marketplace/search/v1/services}ack").text self.assertEqual(ack, "Success") #Move initialization file back to original location system("mv " + alt_conf + " " + std_conf)
def test_alternative_config(self): """ Move configuration file ``config.ini`` to nonstandard location (one level up in directory hierarchy) and try to use the library. """ #Backup the initialization file system("cp " + std_conf + " " + std_conf_back) #Move initialization file to nonstandard location system("mv " + std_conf + " " + alt_conf) #Look where the initialization files really are system("ls " + std_conf) system("ls " + std_conf_back) system("ls " + alt_conf) #Set alternative initialization file set_config_file(alt_conf) #Use the library and test if it works result = findItemsByKeywords(keywords=keywords, paginationInput=paginationInput, encoding=encoding) root = etree.fromstring(result) ack = root.find("{http://www.ebay.com/marketplace/search/v1/services}ack").text self.assertEqual(ack, "Success") #Move initialization file back to original location system("mv " + alt_conf + " " + std_conf)
def search_items(cls, search_term=None, category=None, buyitnow=None, condition=None, max_price=None, Zip=None): logging.info(str(locals())) set_config_file(settings.EBAY_API_SETTINGS_FILE) if not search_term: return [] if not Zip: config = get_config_store() Zip = config.get("settings", "zip") logging.info(Zip) itemFilter = [] if max_price: itemFilter = [{'name': 'MaxPrice', 'value': str(float(max_price)), 'paramName': 'Currency', 'paramValue': 'USD'}] if condition: itemFilter.append({'name': 'Condition', 'value': condition}) outputSelector = ('PictureURLSuperSize', 'SellerInfo') json_str = findItemsByKeywords(keywords=search_term, buyerPostalCode=Zip, itemFilter=itemFilter, outputSelector=outputSelector, aspectFilter=[], domainFilter=[]) # logging.info(json_str) data = json.loads(json_str) items_count = int(cls.item_attr(data, ['findItemsByKeywordsResponse', 0, 'searchResult', 0, '@count'], '0')) if items_count == 0: return [] items = cls.item_attr(data, ['findItemsByKeywordsResponse', 0, 'searchResult', 0, 'item'], []) data_items = [] for item in items: try: processed_item = cls.process_item(item, search_term, category, buyitnow, max_price) except EbayItemError: processed_item = None if processed_item: data_items.append(processed_item) return data_items
def find_item_ids(keywords): "Return a list of, at most 10, valid item IDs." result = findItemsByKeywords(keywords, paginationInput={"entriesPerPage": "10", "pageNumber": "1"}, encoding="XML") # print result root = objectify.fromstring(result) ack = root.ack.text assert ack == "Success" or ack == "Warning" item_ids = [] for itemi in root.searchResult.item: item_ids.append(itemi.itemId.text) # print item_ids return item_ids
def test_regular_config(self): "Test the library with the regular configuration file." #Look where the initialization files really are system("ls " + std_conf) system("ls " + std_conf_back) system("ls " + alt_conf) #should not exist #Use the library and test if it works result = findItemsByKeywords(keywords=keywords, paginationInput=paginationInput, encoding=encoding) root = etree.fromstring(result) ack = root.find("{http://www.ebay.com/marketplace/search/v1/services}ack").text self.assertEqual(ack, "Success")
def doSearch(query, pageNum=1): data = findItemsByKeywords( query, paginationInput={"entriesPerPage": "200", "pageNumber": str(pageNum)}, encoding="XML" ) response = parseString(data) itemNodes = response.getElementsByTagName("item") results = [] for item in itemNodes: itemId = getSingleValue(item, "itemId") itemTitle = getSingleValue(item, "title") itemPrice = getSingleValue(item, "currentPrice") itemEnds = getSingleValue(item, "endTime") results.append((itemId, itemTitle, itemPrice, itemEnds)) return results
def test_regular_config(self): "Test the library with the regular configuration file." #Look where the initialization files really are system(ls_command + std_conf) system(ls_command + std_conf_back) system(ls_command + alt_conf) #should not exist #Use the library and test if it works result = findItemsByKeywords(keywords=keywords, paginationInput=paginationInput, encoding=encoding) root = etree.fromstring(result) ack = root.find( "{http://www.ebay.com/marketplace/search/v1/services}ack").text self.assertEqual(ack, "Success")
def test_findItemsByKeywords(self): result = findItemsByKeywords( keywords=keywords, affiliate=affiliate, \ buyerPostalCode=buyerPostalCode, \ paginationInput=paginationInput, \ sortOrder=sortOrder, \ aspectFilter=aspectFilter, \ domainFilter=domainFilter, \ itemFilter=itemFilter, \ outputSelector=outputSelector, \ encoding=encoding) # print result root = etree.fromstring(result) ack = root.find("{http://www.ebay.com/marketplace/search/v1/services}ack").text self.assertEqual(ack, "Success") #Number of Items between 0 and 10, because of paginationInput res_items = root.find("{http://www.ebay.com/marketplace/search/v1/services}searchResult") self.assertTrue(0 <= len(res_items) <= 10)
def download_xml(keywords, entries_per_page=10, page_number=1, min_price=None, max_price=None, currency="EUR", time_from=None, time_to=None): """ Perform findItemsByKeywords call to Ebay over Internet. time_from, time_to: datetime in UTC """ assert isinstance(time_from, (datetime, NoneType)) assert isinstance(time_to, (datetime, NoneType)) #http://developer.ebay.com/Devzone/finding/CallRef/types/ItemFilterType.html item_filter = [] if min_price: item_filter.append({"name":"MinPrice", "value":str(min_price), "paramName":"Currency", "paramValue":currency}) if max_price: item_filter.append({"name":"MaxPrice", "value":str(max_price), "paramName":"Currency", "paramValue":currency}) #Times in UTC if time_from: item_filter.append({"name":"EndTimeFrom", "value": time_from.strftime("%Y-%m-%dT%H:%M:%S.000Z")}) if time_to: item_filter.append({"name":"EndTimeTo", "value": time_to.strftime("%Y-%m-%dT%H:%M:%S.000Z")}) res_xml = eb_find.findItemsByKeywords( keywords=keywords, # buyerPostalCode, paginationInput= {"entriesPerPage": str(int(entries_per_page)), "pageNumber": str(int(page_number))}, sortOrder="EndTimeSoonest", itemFilter = item_filter, # outputSelector, # SellerInfo encoding="XML") # print res_xml return res_xml
""" Show haow to use alternative configuration files. """ from os import system from os.path import join, dirname, abspath from ebay.utils import set_config_file from ebay.finding import findItemsByKeywords #Create file paths that are relative to the location of this file. def relative(*paths): return abspath(join(dirname(abspath(__file__)), *paths)) #File paths std_conf = relative("../ebay/config.ini") alt_conf = relative("../config.apikey") #Copy initialization file to nonstandard location system("cp " + std_conf + " " + alt_conf) #Look where the initialization files really are system("ls " + std_conf) system("ls " + alt_conf) #Set alternative configuration file and use the library set_config_file(alt_conf) print findItemsByKeywords(keywords="ipod", encoding="XML", paginationInput = {"entriesPerPage": "5", "pageNumber" : "1"})
from os import system from os.path import join, dirname, abspath from ebay.utils import set_config_file from ebay.finding import findItemsByKeywords #Create file paths that are relative to the location of this file. def relative(*paths): return abspath(join(dirname(abspath(__file__)), *paths)) #File paths std_conf = relative("../ebay/config.ini") alt_conf = relative("../config.apikey") #Copy initialization file to nonstandard location system("cp " + std_conf + " " + alt_conf) #Look where the initialization files really are system("ls " + std_conf) system("ls " + alt_conf) #Set alternative configuration file and use the library set_config_file(alt_conf) print findItemsByKeywords(keywords="ipod", encoding="XML", paginationInput={ "entriesPerPage": "5", "pageNumber": "1" })
from ebay.finding import getSearchKeywordsRecommendation, findItemsByKeywords, findItemsByCategory, findItemsAdvanced, findItemsByProduct, findItemsIneBayStores, getHistograms print getSearchKeywordsRecommendation(encoding="XML", keywords="acordian") print findItemsByKeywords(keywords="ipod") print findItemsByCategory(categoryId="123") print findItemsAdvanced() print findItemsByProduct(productId="123") print findItemsIneBayStores() print getHistograms(categoryId="12")
## installing ebay-python. I tried a couple of differnt python ebay packages. this one worked ## I had to do a manual install of something like libxml that wouldn't install by default. I ## had to track-down the windows installer for that library. The output of the program is in ## a format called JSON. from ebay.finding import getSearchKeywordsRecommendation, findItemsByKeywords, findItemsByCategory, findItemsAdvanced, findItemsByProduct, findItemsIneBayStores, getHistograms from ebay.shopping import GetSingleItem import json items = [] wow = findItemsByKeywords(keywords="gopro hero bacpac") wow = json.loads(wow) #items = int(wow['findItemsByKeywordsResponse'][0]['searchResult'][0]['@count']) for i in wow['findItemsByKeywordsResponse'][0]['searchResult'][0]['item']: print i['title'][0] + ' ' + \ i['sellingStatus'][0]['currentPrice'][0]['__value__'] + ' ' + i['itemId'][0] items.append(i['itemId'][0]) for i in items: wow = GetSingleItem(i, include_selector='Description') print wow
## installing ebay-python. I tried a couple of differnt python ebay packages. this one worked ## I had to do a manual install of something like libxml that wouldn't install by default. I ## had to track-down the windows installer for that library. The output of the program is in ## a format called JSON. from ebay.finding import getSearchKeywordsRecommendation, findItemsByKeywords, findItemsByCategory, findItemsAdvanced, findItemsByProduct, findItemsIneBayStores, getHistograms import json wow = findItemsByKeywords(keywords="sportwerks recoil") wow = json.loads(wow) items = int(wow['findItemsByKeywordsResponse'][0]['searchResult'][0]['@count']) for i in range(items): print wow['findItemsByKeywordsResponse'][0]['searchResult'][0]['item'][i]['title'][0] + ' ' + \ wow['findItemsByKeywordsResponse'][0]['searchResult'][0]['item'][i]['sellingStatus'][0]['currentPrice'][0]['__value__']