Add currency display page
This commit is contained in:
@@ -5,7 +5,7 @@ import shutil
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
from d2warehouse.item import Item, Quality
|
from d2warehouse.item import Item, Quality, lookup_basetype
|
||||||
from d2warehouse.parser import parse_stash
|
from d2warehouse.parser import parse_stash
|
||||||
import d2warehouse.db as base_db
|
import d2warehouse.db as base_db
|
||||||
from d2warehouse.app.db import get_db, close_db
|
from d2warehouse.app.db import get_db, close_db
|
||||||
@@ -22,6 +22,59 @@ DB_FILES = {
|
|||||||
"softcore": "d2warehouse.softcore.sqlite3",
|
"softcore": "d2warehouse.softcore.sqlite3",
|
||||||
"hardcore": "d2warehouse.hardcore.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:
|
def d2_running() -> bool:
|
||||||
@@ -258,3 +311,29 @@ def storage_take_items(stash_name: str):
|
|||||||
tmp_path.replace(stash_path)
|
tmp_path.replace(stash_path)
|
||||||
|
|
||||||
return redirect(f"/storage/{stash_name}", code=303)
|
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/<stash_name>/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
|
||||||
|
)
|
||||||
|
|||||||
@@ -12,6 +12,19 @@ body {
|
|||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.currencies {
|
||||||
|
display: flex;
|
||||||
|
gap: 50px
|
||||||
|
}
|
||||||
|
|
||||||
|
.currencies th {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.currencies td {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 1600px) {
|
@media (max-width: 1600px) {
|
||||||
.stash-tab {
|
.stash-tab {
|
||||||
grid-template-columns: repeat(4, 1fr);
|
grid-template-columns: repeat(4, 1fr);
|
||||||
|
|||||||
Reference in New Issue
Block a user