From acd9082772d2a1285b1a40e7b2867f618c5cf662 Mon Sep 17 00:00:00 2001 From: IUSTINA KVRIVISHVILI <62885041+YustinaKvr@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:43:41 +0100 Subject: [PATCH] add eraser for csv (#56) add eraser for csv Add func to manipulate internal_services.csv file Reviewed-by: Artem Sh. --- gitea_info.py | 4 +++- otc_services_dict.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gitea_info.py b/gitea_info.py index b5b4a89..ebd6a7e 100644 --- a/gitea_info.py +++ b/gitea_info.py @@ -47,6 +47,8 @@ def csv_erase(filenames): if file_path.exists(): file_path.unlink() logging.info(f"CSV {filename} has been deleted") + else: + continue except Exception as e: logging.error(f"CSV erase: error has been occured: {e}") @@ -538,7 +540,7 @@ def main(org, gh_org, rtctable, opentable, string, token): if done: logging.info("Github operations successfully done!") - csv_erase(["proposalbot_prs.csv", "doc_exports_prs.csv", "orphaned_prs.csv", "internal_services.csv"]) + csv_erase(["proposalbot_prs.csv", "doc_exports_prs.csv", "orphaned_prs.csv"]) end_time = time.time() execution_time = end_time - start_time minutes, seconds = divmod(execution_time, 60) diff --git a/otc_services_dict.py b/otc_services_dict.py index e00a6f6..2982e57 100644 --- a/otc_services_dict.py +++ b/otc_services_dict.py @@ -6,6 +6,7 @@ import time import logging import csv +import pathlib logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') @@ -29,6 +30,17 @@ db_password = os.getenv("DB_PASSWORD") +def csv_erase(filenames): + try: + for filename in filenames: + file_path = pathlib.Path(filename) + if file_path.exists(): + file_path.unlink() + logging.info(f"CSV {filename} has been deleted") + except Exception as e: + logging.error(f"CSV erase: error has been occured: {e}") + + def connect_to_db(db): logging.info(f"Connecting to Postgres ({db})...") try: @@ -314,6 +326,8 @@ def main(base_dir, rtctable, doctable, styring_path): base_rtc_table = "repo_title_category" base_doc_table = "doc_types" + csv_erase("internal_services.csv") + main(base_dir_regular, base_rtc_table, base_doc_table, styring_url_regular) main(base_dir_swiss, f"{base_rtc_table}_swiss", f"{base_doc_table}_swiss", styring_url_swiss) conn_csv = connect_to_db(db_csv) @@ -322,6 +336,8 @@ def main(base_dir, rtctable, doctable, styring_path): conn_csv.commit() conn_csv.close() + csv_erase("internal_services.csv") + end_time = time.time() execution_time = end_time - start_time minutes, seconds = divmod(execution_time, 60)