Spaces:
Build error
Build error
File size: 1,482 Bytes
3b4b1fb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import json
try:
with open("data/data.json", "r", encoding="UTF-8") as file:
data: dict = json.load(file)
except:
raise "Error ao carregar config.json"
def extrair_dados_template(template: dict = data):
try:
if "template" not in template:
raise KeyError("'template' não encontrado no dicionário.")
template_data = template["template"]
descricao: str = template_data.get("description", "Descrição não disponível.")
if "rules" not in template_data:
raise KeyError("'rules' não encontrado em 'template'.")
regras: str = "\n".join([f"- {rule}" for rule in template_data["rules"]])
if "behavior" not in template_data:
raise KeyError("'behavior' não encontrado em 'template'.")
comportamento = []
for key, value in template_data["behavior"].items():
if key == "examples" and isinstance(value, list):
exemplos = "\n".join([f" * {ex}" for ex in value])
comportamento.append(f"- {key.capitalize()}:\n{exemplos}")
else:
comportamento.append(f"- {key.capitalize()}: {value}")
comportamento_str = "\n".join(comportamento)
return descricao, regras, comportamento_str
except KeyError as e:
print(f"Erro ao acessar a chave: {e}")
return None
"""
descricao, regra, compoa = extrair_dados_template()
print(descricao)
print(regra)
print(compoa)
"""
|