From 9057f81d5f569dc6788d6c5c8c18c673c4d6a294 Mon Sep 17 00:00:00 2001 From: omicron Date: Mon, 30 Oct 2023 12:48:30 +0100 Subject: [PATCH] Add currency display page --- d2warehouse/app/main.py | 81 +++++++++++++++++++++++++++++++- d2warehouse/app/static/style.css | 13 +++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/d2warehouse/app/main.py b/d2warehouse/app/main.py index 03dfb9b..68e2725 100644 --- a/d2warehouse/app/main.py +++ b/d2warehouse/app/main.py @@ -5,7 +5,7 @@ import shutil from datetime import datetime import psutil -from d2warehouse.item import Item, Quality +from d2warehouse.item import Item, Quality, lookup_basetype from d2warehouse.parser import parse_stash import d2warehouse.db as base_db from d2warehouse.app.db import get_db, close_db @@ -22,6 +22,59 @@ DB_FILES = { "softcore": "d2warehouse.softcore.sqlite3", "hardcore": "d2warehouse.hardcore.sqlite3", } +CURRENCY_RUNES = [f"r{i + 1:02d}" for i in range(33)] +CURRENCY_GEMS = [ + "gcv", + "gfv", + "gsv", + "gzv", + "gpv", + "gcb", + "gfb", + "gsb", + "glb", + "gpb", + "gcg", + "gfg", + "gsg", + "glg", + "gpg", + "gcr", + "gfr", + "gsr", + "glr", + "gpr", + "gcw", + "gfw", + "gsw", + "glw", + "gpw", + "gcy", + "gfy", + "gsy", + "gly", + "gpy", + "skc", + "skf", + "sku", + "skl", + "skz", +] +CURRENCY_KEYS = [ + "pk1", + "pk2", + "pk3", + "bey", + "mbr", + "dhn", +] +CURRENCY_ESSENCES = [ + "tes", + "ceh", + "bet", + "fed", + "toa", +] def d2_running() -> bool: @@ -258,3 +311,29 @@ def storage_take_items(stash_name: str): tmp_path.replace(stash_path) return redirect(f"/storage/{stash_name}", code=303) + + +def storage_currency_counts(item_codes: list[str], stash_name: str) -> dict: + db = get_stash_db(stash_name) + currencies = {} + for code in item_codes: + currencies[code] = { + "count": db.execute( + "SELECT COUNT(id) FROM item WHERE code = ?", (code,) + ).fetchone()[0], + "name": lookup_basetype(code)["name"], + } + return currencies + + +@app.route("/storage//currency") +def storage_currency(stash_name: str): + if stash_name not in DB_FILES: + abort(404) + runes = storage_currency_counts(CURRENCY_RUNES, stash_name) + gems = storage_currency_counts(CURRENCY_GEMS, stash_name) + keys = storage_currency_counts(CURRENCY_KEYS, stash_name) + essences = storage_currency_counts(CURRENCY_ESSENCES, stash_name) + return render_template( + "currency.html", runes=runes, gems=gems, keys=keys, essences=essences + ) diff --git a/d2warehouse/app/static/style.css b/d2warehouse/app/static/style.css index 7a9e991..fe92afe 100644 --- a/d2warehouse/app/static/style.css +++ b/d2warehouse/app/static/style.css @@ -12,6 +12,19 @@ body { margin: 0 auto; } +.currencies { + display: flex; + gap: 50px +} + +.currencies th { + text-align: left; +} + +.currencies td { + text-align: right; +} + @media (max-width: 1600px) { .stash-tab { grid-template-columns: repeat(4, 1fr);