From a9839e64bfa1f9b6828eef971adc9427b0055846 Mon Sep 17 00:00:00 2001 From: aulojor Date: Sat, 15 Nov 2025 22:26:26 -0100 Subject: [PATCH] feat: substituir guardar_json pelo utils.save_as_json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mudei um pouco o save_as_json e talvez tenha ficado um pouco nojento porque não sabia muito bem como fazer uso das EVENT_COLS e STATION_COLS de dentro do utils.py --- earthquakes.py | 2 +- utils/utils.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/earthquakes.py b/earthquakes.py index 5618968..a122bb5 100644 --- a/earthquakes.py +++ b/earthquakes.py @@ -137,7 +137,7 @@ def main(): fname = _get_usr_input("Nome do ficheiro a guardar? ") if fname is None: fname = "valores.json" - guardar_json(db, fname) + utils.save_as_json(db, fname, EVENT_COLS, STATION_COLS) else: retInfo = "Base de dados não encontrada!" diff --git a/utils/utils.py b/utils/utils.py index 2bca49b..1e04fd7 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -9,9 +9,10 @@ from typing import Any import pandas as pd -def save_as_json(info: dict[str, Any]) -> bool: - with open("test.json", "w") as fp: - json.dump(info, fp) +def save_as_json(df: pd.DataFrame, fname, event_cols, station_cols) -> bool: + info = create_dict_struct(df, event_cols, station_cols) + with open(fname, "w") as fp: + json.dump(info, fp, indent=4) return True