Last active
February 14, 2017 02:39
-
-
Save clintmjohnson/901aa43287b8b8e4732e to your computer and use it in GitHub Desktop.
Find Items in eBay Stores.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding=utf8 # This eliminates issues with Unicode errors that I was previously encountering. | |
import sys | |
reload(sys) | |
sys.setdefaultencoding('utf8') | |
from ebaysdk.finding import Connection as Finding | |
import csv | |
"""The first function only finds a total page count. This func outputs the Page count, | |
and will be used as Range in the next Func.""" | |
storetosearch = 'storenamehere' | |
def numberofpages(): | |
api = Finding(config_file='ebay.yaml') | |
api_request = dict(storeName=storetosearch) | |
response = api.execute('findItemsIneBayStores', api_request) | |
numberpages = response.dict() | |
return int(numberpages['paginationOutput']['totalPages'])+1 | |
def ebaysellerapi(pages): | |
for p in pages: | |
api = Finding(config_file='ebay.yaml') | |
api_request = dict(storeName=storetosearch, | |
paginationInput={'entriesPerPage': '100', 'pageNumber': str(p)}, | |
outputSelector=['GalleryInfo', 'PictureURLSuperSize']) | |
response = api.execute('findItemsIneBayStores', api_request) | |
ebayoutput1 = response.dict() | |
ebayoutput2 = ebayoutput1['searchResult']['item'] | |
productid1 = [] | |
for product in ebayoutput2: | |
try: | |
productid = product['itemId'] | |
productid1.append(productid) | |
except KeyError: | |
continue | |
largeimage1 = [] | |
for product in ebayoutput2: | |
try: | |
largeimage = product['pictureURLSuperSize'] | |
largeimage1.append(largeimage) | |
except KeyError: | |
continue | |
producttitle1 = [] | |
for product in ebayoutput2: | |
try: | |
producttitle = product['title'] | |
producttitle1.append(producttitle) | |
except KeyError: | |
continue | |
categoryid1 = [] | |
for product in ebayoutput2: | |
categoryid = product['primaryCategory']['categoryId'] | |
categoryid1.append(categoryid) | |
itemprice1 = [] | |
for product in ebayoutput2: | |
try: | |
itemprice = product['sellingStatus']['currentPrice']['value'] | |
itemprice1.append(itemprice) | |
except KeyError: | |
continue | |
itemurl1 = [] | |
for product in ebayoutput2: | |
try: | |
itemurl = product['viewItemURL'] | |
itemurl1.append(itemurl) | |
except KeyError: | |
continue | |
rows = zip(productid1,producttitle1,categoryid1,itemprice1,itemurl1,largeimage1) | |
with open(storetosearch+'_ebay_listings'+'.csv', 'ab') as f: | |
writer = csv.writer(f) | |
for row in rows: | |
writer.writerow(row) | |
ebaysellerapi(range(1,numberofpages())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment