From b64e2f74c1ba766d1e133a65ea6c7e085910bf1c Mon Sep 17 00:00:00 2001 From: spbeach46 Date: Sun, 18 Oct 2020 15:32:17 -0700 Subject: [PATCH] had to convert inputs to ints and correct filenotfounderror in get_ids_from_cats fuction --- ebay_api.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ebay_api.py b/ebay_api.py index 20f328c..a9857df 100644 --- a/ebay_api.py +++ b/ebay_api.py @@ -42,13 +42,13 @@ class FindingApi: ''' data = self.get_data() itemid_results_list = [] - try: + 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: itemid_results_list.append(item['itemId'][0]) # itemId # values are in lists for some reason - except pd.errors.EmptyDataError: + except (pd.errors.EmptyDataError, FileNotFoundError): for item in data['findItemsByCategoryResponse'][0]['searchResult'][0]['item']: itemid_results_list.append(item['itemId'][0]) item_id_results = [','.join(itemid_results_list[n:n+20]) for n in list(range(0, @@ -77,20 +77,24 @@ class ShoppingApi: response = requests.get("https://open.api.ebay.com/shopping?", params=params) data = response.json() - return data + return data # TODO save data as file?? class CurateData: ''' Contains functions for curating data for machine learning training sets ''' def update_df(self, data): + ''' + Extracts itemIds and name-value list , creates new dict and appends df + ''' names = [] values = [] - nvl = data['Item'][0]['ItemSpecifics']['NameValueList'][0] + nvl = data['Item'][0]['ItemSpecifics']['NameValueList'][0]# TODO is this only for one item? for nvl_dict in nvl: names.append(nvl_dict['Name']) - values.append(nvl_dict['Value']) # TODO Try to excract value from list here + values.append(nvl_dict['Value']) + # TODO Also append itemId and value to the dictionary nvl_dict = dict(zip(names, values)) data.update(nvl_dict) @@ -103,6 +107,8 @@ def main(): ebay listings ''' service, pageNumber = input('service and pageNumber:').split() + service = int(service) + pageNumber = int(pageNumber) finding = FindingApi(service, pageNumber) item_id_results = finding.get_ids_from_cats() shopping = ShoppingApi()