removed some linting errors and figured out how to add dicts to pandas df (see shopping_test.py comments

This commit is contained in:
spbeach46 2020-10-04 00:48:55 -07:00
parent 116dcfcdd6
commit 752fa7efaa
2 changed files with 13 additions and 5 deletions

View File

@ -7,14 +7,17 @@ import pandas as p
with open('cat_list.txt') as jf:
cat_list = json.load(jf)
finding_service = ['findItemsAdvanced', 'findCompletedItems', 'findItemsByKeywords', 'findItemsIneBayStores', 'findItemsByCategory', 'findItemsByProduct'] # list(set(re.findall(r'find\w+', response.text)))
finding_service = ['findItemsAdvanced', 'findCompletedItems', 'findItemsByKeywords', 'findItemsIneBayStores', 'findItemsByCategory', 'findItemsByProduct']
pageNumber = list(range(1,101))
# departments = ["3034","93427"]
item_results_list = []
for categoryID in cat_list:
itemid_results_list = []
for categoryID in cat_list[0:2]:
params = {
"OPERATION-NAME":finding_service[4],
"SECURITY-APPNAME":"scottbea-xlister-PRD-6796e0ff6-14862949",
"SECURITY-APPNAME":"scottbea-xlister-PRD-6796e0ff6-14862949",
"SERVICE-VERSION":"1.13.0",
"RESPONSE-DATA-FORMAT":"JSON",
"categoryId":categoryID ,
@ -23,7 +26,7 @@ for categoryID in cat_list:
}
# extract item id here for piping into shopping_test.py
response = requests.get("https://svcs.ebay.com/services/search/FindingService/v1", params=params) #
response = requests.get("https://svcs.ebay.com/services/search/FindingService/v1", params=params)
data = response.json()
pretty_data = json.dumps(data, indent=2)
# can use pandas.json_normalize(custom dict cobbled from respons.json())

View File

@ -24,4 +24,9 @@ for nvl_dict in nvl:
values.append(nvl_dict['Value'])
nvl_dict = dict(zip(names, values))
data.update(nvl_dict)
df = pd.json_normalize(data)
df.to_csv('big_data.csv')
# to append items to the pandas dataframe/csv, use var = df.append(json/dict, ignore_index=True)
# you will have to redefine var as a new dataframe everytime, too for some reason (I'm wondering
# if this is a bug?).