xlister/id_update.py

67 lines
2.0 KiB
Python

import os
import requests
import json
import ebaysdk
from ebaysdk.trading import Connection as Trading
from ebaysdk.finding import Connection as Finding
import time
import concurrent.futures
# (categoryId = women's shoes = 3034)
# Initialize loop to get number of pages needed in for loop
start = time.time()
fapi = Finding(config_file = "ebay.yaml")
tapi = Trading(config_file = 'ebay.yaml')
fresponse = fapi.execute('findItemsAdvanced', {'itemFilter':{'name':'Seller','value':'chesshoebuddy'}, 'categoryId':'3034', 'paginationInput':{'entriesPerPage':'100','pageNumber':'1'}}).dict()
page_results = int(fresponse['paginationOutput']['totalPages'])
pages = []
for i in range(0, page_results):
i += 1
pages.append(i)
''' Begin definitions for getting ItemIds and SKU: '''
def id_up(n):
ids = []
fresponse = fapi.execute('findItemsAdvanced', {'itemFilter':{'name':'Seller','value':'chesshoebuddy'}, 'categoryId':'3034', 'paginationInput':{'entriesPerPage':'100','pageNumber':str(n)}}).dict()
for item in (fresponse['searchResult']['item']):
itemID = item['itemId']
#response = tapi.execute('GetItem',{'ItemID':itemID}).dict()
ids.append(itemID)
print(ids)
return ids
'''def sku_up(itemID):
response = tapi.execute('GetItem',{'ItemID':itemID}).dict()
try:
sku = response['Item']['SKU']
except KeyError:
sku = 'missing'
return sku'''
def main():
ids = []
skus = []
with concurrent.futures.ThreadPoolExecutor() as executor:
for future in executor.map(id_up, pages):
ids.extend(future)
with open('ebay_ids.txt', 'w') as outfile:
json.dump(ids, outfile)
'''with concurrent.futures.ProcessPoolExecutor() as executor:
for future in executor.map(sku_up, ids):
skus.append(future)
with open('ebay_skus.txt', 'w') as outfile:
json.dump(skus, outfile)'''
if __name__ == '__main__':
main()
'''ebay_id_dict = dict(zip(ids, skus))
with open('ebay_id_dict.txt', 'w') as outfile:
json.dump(ebay_id_dict, outfile)'''