My eBay item.get() request does not retrieve anything for the seller description and goes straight to my error message displayed when not found .all other parts do return a value - I want the seller description to be shown under item name.
I tried changing the description to Item.Description , textdescription - nothing works - also tried .get('value') at the end of it.
import pandas as pd
from ebaysdk.finding import Connection as Finding
from ebaysdk.exception import ConnectionError
from IPython.display import display, HTML
APPLICATION_ID = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
def get_user_input():
# Get user input for the search keyword
search_keyword = input("Enter the item you want to search for: ")
return search_keyword
def get_category_id(api, search_keyword):
try:
# Use findItemsByKeywords to get category information
response = api.execute('findItemsByKeywords', {'keywords': search_keyword})
items = response.dict().get('searchResult', {}).get('item', [])
# Choose the first item's category as an example; you may want to implement logic to handle multiple items
return items[0].get('primaryCategory', {}).get('categoryId')
except ConnectionError as e:
print(e)
print(e.response.dict())
def get_results(api, payload):
try:
response = api.execute('findItemsAdvanced', payload)
return response.dict()
except ConnectionError as e:
print(e)
print(e.response.dict())
def search_ebay(api, search_keyword, category_id):
payload = {
'keywords': search_keyword,
'categoryId': [category_id],
'itemFilter': [
{'name': 'LocatedIn', 'value': 'GB'},
],
'sortOrder': 'StartTimeNewest',
}
results = get_results(api, payload)
if results is not None:
total_pages = get_total_pages(results)
items_list = results['searchResult']['item']
i = 2
while i <= total_pages:
payload['paginationInput'] = {'entriesPerPage': 100, 'pageNumber': i}
results = get_results(api, payload)
items_list.extend(results['searchResult']['item'])
i += 1
df_items = pd.DataFrame(columns=['currentPrice', 'viewItemURL', 'primaryCategory', 'galleryURL', 'title', 'description'])
for item in items_list[:3]: # Display only the first 3 items
row = {
'currentPrice': item.get('sellingStatus').get('currentPrice').get('value'),
'viewItemURL': item.get('viewItemURL'),
'primaryCategory': item.get('primaryCategory', {}).get('categoryName'),
'galleryURL': item.get('galleryURL'),
'title': item.get('title', 'N/A'), # Get the title or use 'N/A' if not available
'description': item.get('TextDescription', 'No description available'), # Get the description or use a default if not available
}
df_items = pd.concat([df_items, pd.DataFrame([row], columns=df_items.columns)], ignore_index=True)
return df_items
else:
print("No results found.")
return pd.DataFrame() # Return an empty DataFrame if no results
def get_total_pages(results):
if results and 'paginationOutput' in results and 'totalPages' in results['paginationOutput']:
return int(results['paginationOutput']['totalPages'])
else:
return 0
# Initialize the API connection
api = Finding(siteid='EBAY-GB', appid=APPLICATION_ID, config_file=None)
# Get user input for the search keyword
search_keyword = get_user_input()
# Get category ID dynamically based on the user's search term
category_id = get_category_id(api, search_keyword)
if category_id is not None:
# Search eBay based on user input
df_items = search_ebay(api, search_keyword, category_id)
# Sort the DataFrame before selecting the first three items
df_items_sorted = df_items.sort_values(by='currentPrice')
# Display the HTML content with clickable links and images for the first three items
pd.set_option('display.max_colwidth', None) # Show full content of columns, like URLs
display(HTML(f"<h2>Top 3 Results for '{search_keyword}'</h2>"))
display(HTML(df_items_sorted.head(3).to_html(escape=False)))
# Display the cheapest item with all details in a formatted box
cheapest_item = df_items_sorted.iloc[0]
display(HTML(f"""
<h2>Cheapest Item</h2>
<div style="border: 2px solid #4CAF50; padding: 10px; margin-top: 20px; max-width: 400px; border-radius: 10px;">
<img src="{cheapest_item['galleryURL']}" alt="Cheapest Item" style="max-width: 100%; border: 2px solid grey; border-radius: 8px;">
<p style="font-size: 16px; font-weight: bold; margin-top: 10px;">Price: £{cheapest_item['currentPrice']}</p>
<p style="font-size: 14px;">Product: {cheapest_item['title']}</p>
<p style="font-size: 12px;">Description: {cheapest_item['description']}</p>
<p style="font-size: 14px;"><a href="{cheapest_item['viewItemURL']}" target="_blank">View Item</a></p>
</div>
"""))
else:
print("Unable to determine category ID.")
My error is here - at least I think so:
'description': item.get('TextDescription', 'No description available'), # Get the description or use a default if not available