updating update_cats for oauth
This commit is contained in:
parent
29800af1d4
commit
e766a1ba9d
31
ebay_api.py
31
ebay_api.py
@ -39,18 +39,26 @@ class ShoppingApi:
|
||||
|
||||
for department in parent_cats:
|
||||
|
||||
params = {
|
||||
"callname":"GetCategoryInfo",
|
||||
"X-EBAY-API-IAF-TOKEN":cfg.sec['X-EBAY-API-IAF-TOKEN'],
|
||||
# params = {
|
||||
# "callname":"GetCategoryInfo",
|
||||
# "X-EBAY-API-IAF-TOKEN":cfg.sec['X-EBAY-API-IAF-TOKEN'],
|
||||
# "version":"671",
|
||||
# "responseencoding":"JSON",
|
||||
# "CategoryID":department,
|
||||
# "IncludeSelector":"ChildCategories",
|
||||
# }
|
||||
|
||||
headers = {
|
||||
"X-EBAY-API-IAF-TOKEN":cfg.sec['X-EBAY-API-IAF-TOKEN'], # TODO implement auto oauth token renewal
|
||||
"version":"671",
|
||||
"responseencoding":"JSON",
|
||||
"CategoryID":department,
|
||||
"IncludeSelector":"ChildCategories",
|
||||
}
|
||||
|
||||
url = "https://open.api.ebay.com/shopping?&callname=GetCategoryInfo&responseencoding=JSON&IncludeSelector=ChildCategories&CategoryID="+department
|
||||
|
||||
try:
|
||||
response = requests.get("https://open.api.ebay.com/shopping?", params=params, timeout=4)
|
||||
response = requests.get(url, headers=headers, timeout=4)
|
||||
response.raise_for_status()
|
||||
return response
|
||||
|
||||
except requests.exceptions.RequestException:
|
||||
print('connection error')
|
||||
@ -61,7 +69,7 @@ class ShoppingApi:
|
||||
temp_cat_list = [cat['CategoryID'] for cat in response]
|
||||
cat_list.extend(temp_cat_list)
|
||||
|
||||
with open('cat_list.txt', 'w') as f:
|
||||
with open('cat_list1.txt', 'w') as f:
|
||||
json.dump(cat_list, f)
|
||||
|
||||
# leaf_list = [node['LeafCategory'] for node in response]
|
||||
@ -72,9 +80,6 @@ class ShoppingApi:
|
||||
Gets raw JSON data from multiple live listings given multiple itemIds
|
||||
'''
|
||||
|
||||
with open('item_id_results.txt') as f:
|
||||
item_id_results = json.load(f)
|
||||
|
||||
headers = {
|
||||
"X-EBAY-API-IAF-TOKEN":cfg.sec['X-EBAY-API-IAF-TOKEN'], # TODO implement auto oauth token renewal
|
||||
"version":"671",
|
||||
@ -85,18 +90,16 @@ class ShoppingApi:
|
||||
try:
|
||||
# random sleep here between 0 and 10 secs?
|
||||
|
||||
sleep(randint(1,10)) # may not be necessary
|
||||
# sleep(randint(1,10)) # may not be necessary
|
||||
response = requests.get(url, headers=headers,timeout=24)
|
||||
response.raise_for_status()
|
||||
response = response.json()
|
||||
response = response['Item']
|
||||
print('index number {}'.format(item_id_results.index(twenty_id)))
|
||||
print(response)
|
||||
|
||||
|
||||
except (requests.exceptions.RequestException, KeyError):
|
||||
print('connection error. IP limit possibly exceeded')
|
||||
print('index number {}'.format(item_id_results.index(twenty_id)))
|
||||
return # returns NoneType. Handle at conky()
|
||||
|
||||
return response
|
||||
|
Loading…
Reference in New Issue
Block a user