import json
import pandas as pd
from ebaysdk.finding import Connection as finding
from bs4 import BeautifulSoup
from config import app_id
Keywords = input('Enter your keyword/s Ex: Thinkpad t470:''\n')
api = finding(appid = app_id, siteid='EBAY-US', config_file=None)
api_request = { 'keywords': Keywords, 'outputSelector' : 'SellerInfo' }
response = api.execute('findItemsByKeywords', api_request)
soup = BeautifulSoup(response.content, 'lxml')
totalentries = int(soup.find('totalentries').text)
items = soup.find_all('item')
# Create a list to store data
data = []
def res_print():
for item in items:
title = item.title.string.lower().strip()
price = int(round(float(item.currentprice.string)))
url = item.viewitemurl.string.lower()
seller = item.sellerusername.text.lower()
listingtype = item.listingtype.string.lower()
# Check if the listing type is fixed price
if listingtype == 'fixedprice':
# Add data to the list as dictionaries
data.append({
'Title': title,
'Price': price,
'URL': url,
'Seller': seller,
'Listing Type': listingtype
})
# Sort the items by price from lowest to highest
items.sort(key=lambda x: float(x.currentprice.string))
res_print()
# Create a DataFrame from the dictionary list
df = pd.DataFrame(data)
# Export the DataFrame as a CSV file
df.to_csv('ebay_results.csv', index=False)
dfStyler = df.style.set_properties(**{'text-align': 'left'})
dfStyler.set_table_styles([dict(selector='th', props=[('text-align', 'left')])])