dl/commands/paimon.py
Michel Roux 5536d2e0c7
All checks were successful
dl / lint (push) Successful in 3m55s
dl / docker (push) Successful in 11m6s
Add paimon
2023-08-22 01:08:06 +02:00

70 lines
1.9 KiB
Python

#!/usr/bin/env python3
import argparse
import csv
import json
import os
import tempfile
import urllib.request
import zipfile
STATIC_TYPE = ["hp", "atk", "def", "em"]
def compute_base(data, type: str, base: float = 0.0):
boost = 0
if type in data:
if type in STATIC_TYPE:
base = data[type][-1]
else:
base = data[type][-1] * 100
if f"{type}Percent" in data:
if type in STATIC_TYPE:
boost = base * data[f"{type}Percent"][-1]
else:
boost = data[f"{type}Percent"][-1] * 100
return round(base + boost)
parser = argparse.ArgumentParser()
parser.add_argument(
"output", help="Path of the output CSV file", type=argparse.FileType("w")
)
args = parser.parse_args()
main, message = urllib.request.urlretrieve(
"https://github.com/MadeBaruna/paimon-moe/archive/refs/heads/main.zip"
)
CHAR_DATA_TMP = tempfile.mkdtemp()
CHAR_DATA_OUT = os.path.join(CHAR_DATA_TMP, "paimon-moe-main/src/data/characterData")
with zipfile.ZipFile(main) as zip:
zip.extractall(CHAR_DATA_TMP)
out = csv.DictWriter(
args.output,
["ID", "PV", "ATQ", "DEF", "Taux CRIT", "DGT CRIT", "EM", "Energy Cost"],
)
out.writeheader()
for file in sorted(os.listdir(CHAR_DATA_OUT)):
with open(os.path.join(CHAR_DATA_OUT, file)) as character:
data = json.load(character)
out.writerow(
{
"ID": data["id"],
"PV": compute_base(data, "hp"),
"ATQ": compute_base(data, "atk"),
"DEF": compute_base(data, "def"),
"Taux CRIT": compute_base(data, "critRate", 5.0),
"DGT CRIT": compute_base(data, "critDamage", 50.0),
"EM": compute_base(data, "em"),
"Energy Cost": data["burst"]["skillStats"][-1][-1][0]
- compute_base(data, "er"),
}
)