Files
my-botty/scripts/make_stash_csv.py
Alex 5c687773b1 Click-and-go install: self-bootstrapping install.bat + tesserocr DLL fix (#2)
Merges fix/stash-full-guard-and-testbed into main. See PR #2 for full description.
2026-06-20 09:27:12 +02:00

64 lines
1.9 KiB
Python

"""Generate a deduplicated trade CSV from the stash scan JSON."""
import json, csv, os, sys
_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PAGE_LABELS = {
0: "personal",
1: "shared_1",
2: "shared_2_uniques_sets",
3: "shared_3",
4: "shared_4",
5: "shared_5",
}
SKIP_LINES = {
"KEEP IN INVENTORY TO GAIN BONUS",
"INSERT SCROLLS",
"RIGHT CLICK TO USE",
}
def make_csv(json_path, out_path):
data = json.load(open(json_path, encoding="utf-8"))
seen = {} # name -> row dict, first occurrence wins
order = []
for page_str, items in sorted(data.items(), key=lambda x: int(x[0])):
page = int(page_str)
seen_pos = set()
for item in items:
name = item["name"]
pos = (item["col"], item["row"])
if pos in seen_pos or not name or name.startswith("("):
continue
seen_pos.add(pos)
if name in seen:
continue
stats_lines = [
ln for ln in item["full_text"].splitlines()
if ln and ln != name and ln not in SKIP_LINES
]
row = {
"name": name,
"page": PAGE_LABELS.get(page, f"shared_{page}"),
"stats": " | ".join(stats_lines),
}
seen[name] = row
order.append(name)
with open(out_path, "w", newline="", encoding="utf-8") as f:
w = csv.DictWriter(f, fieldnames=["name", "page", "stats"])
w.writeheader()
for name in order:
w.writerow(seen[name])
return order, seen
if __name__ == "__main__":
json_in = os.path.join(_root, "log", "stash_inventory.json")
csv_out = os.path.join(_root, "stash_list.csv")
order, seen = make_csv(json_in, csv_out)
print(f"Written {len(order)} unique items -> {csv_out}")
for name in order:
print(f" [{seen[name]['page']}] {name}")