added lambda function to multithreader in FindingApi method

This commit is contained in:
spbeach46 2020-12-25 12:15:20 -07:00
parent d9781579cd
commit 7af5811792

View File

@ -16,17 +16,13 @@ class FindingApi:
# departments = ["3034","93427"] (womens and mens)
def get_data(self, i): # TODO your going to have to use nested functions of lambda functions here somewhere
def get_data(self, category_id, i): # TODO you're going to have to use nested functions of lambda functions here somewhere
'''
Gets raw JSON data fom FindingApi service call
Currently being used to get itemIDs from categories
'''
with open('cat_list.txt') as jf:
cat_list = json.load(jf)
for category_id in cat_list:
params = {
"OPERATION-NAME":self.service,
"SECURITY-APPNAME":"scottbea-xlister-PRD-6796e0ff6-14862949",
@ -36,26 +32,31 @@ class FindingApi:
"paginationInput.entriesPerPage":"100",
"paginationInput.PageNumber":i
}
response = requests.get("https://svcs.ebay.com/services/search/FindingService/v1",
params=params)
params=params)
data = response.json()
return data
def get_ids_from_cats(self):
'''
Creates a 20-itemId list to use for the ShoppingApi
call
'''
with open('cat_list.txt') as jf:
cat_list = json.load(jf)
pages = self.pageNumber
itemid_results_list = []
# TODO instead of running through multiple try except loops try to implement set methods for efficiency and ease. Remember symmetric_difference, difference, intersection, set()
with open('cat_list.txt') as jf:
cat_list = json.load(jf)
for category_id in cat_list:
args = [(category_id, i) for i in pages]
with concurrent.futures.ThreadPoolExecutor() as executor:
for future in executor.map(self.get_data, pages):
for future in executor.map(lambda p: self.get_data(*p), args):
data = future
try:
@ -69,11 +70,13 @@ class FindingApi:
if item not in itemid_results_list:
itemid_results_list.append(item['itemId'][0])
item_id_results = [','.join(itemid_results_list[n:n+20]) for n in list(range(0,
len(itemid_results_list), 20))]
item_id_results = [','.join(itemid_results_list[n:n+20]) for n in list(range(0,
len(itemid_results_list), 20))]
return item_id_results
## TODO instead of running through multiple try except loops try to implement set methods for efficiency and ease. Remember symmetric_difference, difference, intersection, set()
# for category_id in cat_list:
class ShoppingApi:
'''
Creates objects from ShoppingApi service calls that can interact with