update pricing i guess

This commit is contained in:
2025-06-09 12:28:15 -04:00
parent 77d6fd6e29
commit 82fd1cb2da
6 changed files with 268 additions and 61 deletions

View File

@@ -504,3 +504,62 @@ class MarketplaceListingService(BaseService[MarketplaceListing]):
data_rows = [",".join([escape_csv_value(data[tcgplayer_id][header]) for header in headers]) for tcgplayer_id in data]
csv_data = "\n".join([header_row] + data_rows)
return csv_data
async def create_tcgplayer_update_file(self, db: Session, marketplace: Marketplace=None) -> str:
# TCGplayer Id,Product Line,Set Name,Product Name,Title,Number,Rarity,Condition,TCG Market Price,TCG Direct Low,TCG Low Price With Shipping,TCG Low Price,Total Quantity,Add to Quantity,TCG Marketplace Price,Photo URL
headers = [
"TCGplayer Id",
"Product Line",
"Set Name",
"Product Name",
"Title",
"Number",
"Rarity",
"Condition",
"TCG Market Price",
"TCG Direct Low",
"TCG Low Price With Shipping",
"TCG Low Price",
"Total Quantity",
"Add to Quantity",
"TCG Marketplace Price",
"Photo URL"
]
unmanaged_inventory = await self.pricing_service.update_prices_for_unmanaged_inventory(db)
managed_inventory = await self.pricing_service.update_prices_for_managed_inventory(db)
# combine and convert to csv
inventory = unmanaged_inventory + managed_inventory
data = {}
for inventory_item in inventory:
data[inventory_item.tcgplayer_sku_id] = {
"TCGplayer Id": inventory_item.tcgplayer_sku_id,
"Product Line": inventory_item.product_line,
"Set Name": inventory_item.set_name,
"Product Name": inventory_item.product_name,
"Title": inventory_item.title,
"Number": inventory_item.number,
"Rarity": inventory_item.rarity,
"Condition": inventory_item.condition,
"TCG Market Price": inventory_item.tcg_market_price,
"TCG Direct Low": inventory_item.tcg_direct_low,
"TCG Low Price With Shipping": inventory_item.tcg_low_price_with_shipping,
"TCG Low Price": inventory_item.tcg_low_price,
"Total Quantity": "",
"Add to Quantity": "0",
"TCG Marketplace Price": f"{Decimal(inventory_item.tcg_marketplace_price):.2f}",
"Photo URL": ""
}
# format data into csv
# header
header_row = ",".join(headers)
# data
def escape_csv_value(value):
if value is None:
return ""
value = str(value)
if any(c in value for c in [',', '"', '\n']):
return f'"{value.replace('"', '""')}"'
return value
data_rows = [",".join([escape_csv_value(data[tcgplayer_id][header]) for header in headers]) for tcgplayer_id in data]
csv_data = "\n".join([header_row] + data_rows)
return csv_data