import pandas as pd
import re

def getType(text):
    if text == "Hero":
        return "hero"
    elif text == "Villain":
        return "villain"
    elif text == "Super Power":
        return "superpower"
    elif text == "Equipment":
        return "equipment"
    elif text == "Location":
        return "location"
    elif text == "Super-Villain":
        return "supervillain"
    elif text == "Super Hero":
        return "superhero"
    elif text == "Starter":
        return "starter"
    elif text == "None (Weakness)":
        return "weakness"

def getText(text):
    if text == 0:
        return ""
    formatted = re.sub(r"(\+\d+ Poder)", r"<b>\1</b>", text)
    formatted = re.sub(r'(</b>)([A-Z])', r'\1\n\t\t\2', formatted)
    formatted = re.sub(r"(Em Progresso:)", r"<b>\1</b>", formatted)
    formatted = re.sub(r"(Defesa:)", r"<b>\1</b>", formatted)
    formatted = re.sub(r"(Ataque:)", r"<b>\1</b>", formatted)
    formatted = re.sub(r"(\([^)]*\))", r"<i>\1</i>", formatted)
    
    
    return formatted

setList = pd.read_excel("dcdb.ods", sheet_name="FE", engine="odf")
setList.fillna(0, inplace=True)

with open('cards', 'a') as file:
    for index, row in setList.iterrows():
        for card in range(int(row["Copies"])):

            cardType = getType(row["Card Type"])
            cardName = row["Card Name"]
            cardText = getText(row["Card Text"])
            cardVP = row["VP"]
            cardCost = int(row["Cost"])

            cardData =f"""card:\n\thas_styling: false\n\tnotes:\n\ttime_created: 2025-09-07 16:00:00\n\ttime_modified: 2025-09-07 16:01:00\n\tcard_type: {cardType}\n\tname: {cardName}\n\torder: blank\n\tsuper_type:\n\tsub_type:\n\tcard_symbol: DC\n\timage:\n\ttext: \n\t\t{cardText}\n\thonor: {cardVP}\n\tcost: {cardCost}\n"""

            file.write(cardData)