corrected update_df to iterate over items and nvl kv pairs. and began check for repeat results
This commit is contained in:
parent
b64e2f74c1
commit
47b77600a5
25
ebay_api.py
25
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')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user