Spaces:
Sleeping

inventorytracker / reporter.py
YtFenixS's picture
Upload 6 files
270511d verified
Raw History Blame Contribute Delete
2.51 kB
# ══════════════════════════════════════════════════════════════════════════════
# REPORTER β€” terminal output helpers
# ══════════════════════════════════════════════════════════════════════════════
def print_inventory_summary(items: list[dict]) -> None:
"""Pretty-print a full inventory summary to stdout."""
if not items:
print("No items to display.")
return
total_value = sum(i["price"] for i in items)
knives = [i for i in items if i["isKnife"]]
gloves = [i for i in items if i["isGlove"]]
stattrak = [i for i in items if i["type"] == "StatTrak"]
souvenir = [i for i in items if i["type"] == "Souvenir"]
rarity_groups: dict[str, list] = {}
for item in items:
rarity_groups.setdefault(item["rarity"], []).append(item)
sep = "=" * 80
print(f"\n{sep}")
print(" INVENTORY SUMMARY")
print(sep)
print(f"Total items : {len(items)}")
print(f"Total value : ${total_value:.2f}")
print("\nSpecial items:")
print(f" Knives : {len(knives):3} (${sum(k['price'] for k in knives):.2f})")
print(f" Gloves : {len(gloves):3} (${sum(g['price'] for g in gloves):.2f})")
print(f" StatTrak : {len(stattrak):3} (${sum(s['price'] for s in stattrak):.2f})")
print(f" Souvenir : {len(souvenir):3} (${sum(s['price'] for s in souvenir):.2f})")
print("\nRarity distribution:")
for rarity, r_items in sorted(rarity_groups.items(), key=lambda x: len(x[1]), reverse=True):
print(f" {rarity:<20} {len(r_items):3} pcs (${sum(i['price'] for i in r_items):.2f})")
print(f"\n{sep}")
print(" ITEMS (sorted by price, descending)")
print(sep)
for idx, item in enumerate(sorted(items, key=lambda x: x["price"], reverse=True), 1):
special = ""
if item["isKnife"]:
special = " πŸ”ͺ"
elif item["isGlove"]:
special = " 🧀"
if item["type"] == "StatTrak":
special += " ST"
elif item["type"] == "Souvenir":
special += " SV"
print(
f"{idx:3}. ${item['price']:8.2f} | {item['rarity']:<15} | "
f"{item['quality']:<10} | {item['name']:<50}{special}"
)