From 47b77600a5b0994471b8a4cc990be54261450f3c Mon Sep 17 00:00:00 2001 From: spbeach46 Date: Sat, 24 Oct 2020 03:36:31 -0700 Subject: [PATCH] corrected update_df to iterate over items and nvl kv pairs. and began check for repeat results --- ebay_api.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/ebay_api.py b/ebay_api.py index a9857df..a1031b3 100644 --- a/ebay_api.py +++ b/ebay_api.py @@ -45,12 +45,13 @@ class FindingApi: try:# TODO run pdb here to see how to extract itemId before update_df training = pd.read_csv('training.csv') for item in data['findItemsByCategoryResponse'][0]['searchResult'][0]['item']: - if item not in training.values: + if item not in training.values not in itemid_results_list:# TODO need to figure out syntax to check if item_id is present in both list and training set. (list to avoid repeat results) itemid_results_list.append(item['itemId'][0]) # itemId # values are in lists for some reason except (pd.errors.EmptyDataError, FileNotFoundError): for item in data['findItemsByCategoryResponse'][0]['searchResult'][0]['item']: - itemid_results_list.append(item['itemId'][0]) + 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))] @@ -87,17 +88,17 @@ class CurateData: ''' Extracts itemIds and name-value list , creates new dict and appends df ''' - names = [] - values = [] - nvl = data['Item'][0]['ItemSpecifics']['NameValueList'][0]# TODO is this only for one item? + for item in data: + names = [] + values = [] + nvl = data['Item'][0]['ItemSpecifics']['NameValueList'] + for nvl_dict in nvl: + names.append(nvl_dict['Name']) + values.append(nvl_dict['Value']) + # TODO Also append itemId and value to the dictionary somewhere - for nvl_dict in nvl: - names.append(nvl_dict['Name']) - values.append(nvl_dict['Value']) - # TODO Also append itemId and value to the dictionary - - nvl_dict = dict(zip(names, values)) - data.update(nvl_dict) + nvl_dict = dict(zip(names, values)) + data.update(nvl_dict) df = pd.json_normalize(data) df.to_csv('training.csv', mode='a')