had to convert inputs to ints and correct filenotfounderror in get_ids_from_cats fuction

This commit is contained in:
spbeach46 2020-10-18 15:32:17 -07:00
parent 26b425f31c
commit b64e2f74c1

View File

@ -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()