Esempio n. 1
0
    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 test_alternative_config(self):
     """
     Ensure the standard configuration file ``ebay/config.ini`` does not 
     exist, and try to use the library with the alternative configuration 
     file ``tests/config-test1.ini`.
     """
     #Copy original/standard configuration file to backup location
     shutil.copy(std_conf, std_conf_back)
     #Remove the standard configuration file
     os.remove(std_conf)
     
     #Look where the initialization files really are
     os.system("ls -l ../ebay/*.ini") #Should not exist
     os.system("ls -l ../tests/*.ini")
     
     #Set alternative initialization file
     set_config_file(alt_conf)
     
     #Use the library and test if it works
     result = GeteBayTime(encoding="XML")
     root = objectify.fromstring(result)
     ack = root.Ack.text
     self.assertEqual(ack, "Success")
     ebay_time = root.Timestamp.text 
     print ebay_time
     self.assertTrue(len(ebay_time) > 10, 
                     "eBay time is a somewhat long string.")
     
     #Restore the original configuration file from the backup.
     shutil.copy(std_conf_back, std_conf)
Esempio n. 4
0
def init_site(folder="./", siteid = "UK"):
    
    if folder[-1]!='/': folder += '/'

    global API_KEY_FILE
    global EBAY_SITE_FILE
    
    EBAY_SITE_FILE = folder + "ebay.site" + siteid
    set_config_file([API_KEY_FILE, EBAY_SITE_FILE])
Esempio n. 5
0
    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
Esempio n. 6
0
from ebay.utils import set_config_file
from ebay.finding import findItemsAdvanced

import json
import web
import re

set_config_file("ebay.apikey")

urls = (
    '/','list'
)

render = web.template.render('templates/',base='base',globals={
})

class list:
    def GET(self):
        response = json.loads(findItemsAdvanced(
            keywords='lego lbs -mega -manual -instruction',
            sortOrder = 'EndTimeSoonest',
        ))
        
        page = response['findItemsAdvancedResponse'][0]
        results = page['searchResult'][0]
        items = results['item']

        lbs_match = re.compile('.*?([0-9\.\- ]+)[ +]*(lb|pound)',re.I)
        
        items_list = []
Esempio n. 7
0
import unittest
from lxml import etree

from ebay.utils import set_config_file
from ebay.finding import (getSearchKeywordsRecommendation, getHistograms,
                          findItemsAdvanced, findItemsByCategory, 
                          findItemsByKeywords, findItemsByProduct,
                          findItemsIneBayStores)


def relative(*path_fragments):
    'Create a file path that is relative to the location of this file.'
    return path.abspath(path.join(path.dirname(__file__), *path_fragments))

#Tell python-ebay to use the custom configuration file
set_config_file(relative("config-test1.ini"))


#Definitions of the various arguments of the finding API.
encoding = "XML" #default "JSON": Output encoding
keywords = "ipod"
#Get category IDs with function: `ebay.shopping.GetCategoryInfo`
categoryId = "73839" #iPods & MP3 Players
productId = "77767691" #iPod nano 5th gen. Black. Each product has unique ID.
storeName = "Fab Finds 4 U" #A big store that won't go away soon.
#This information is encoded in URLs so the affiliates can get their commission. 
affiliate = {"networkId":"9", "trackingId":"1234567890"}
buyerPostalCode = "10027" #central New York City, USA
#Set number of results per call (here 10). Get additional results by 
#increasing page number.
paginationInput = {"entriesPerPage": "10", "pageNumber": "1"}
"""
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"
                          })
Esempio n. 10
0
 def __init__(self, keyfile):
     assert isinstance(keyfile, (basestring, NoneType))
     if keyfile is not None:
         eb_utils.set_config_file(keyfile)