Skip to content

Commit

Permalink
add eraser for csv (#56)
Browse files Browse the repository at this point in the history
add eraser for csv

Add func to manipulate internal_services.csv file

Reviewed-by: Artem Sh.
  • Loading branch information
YustinaKvr committed Mar 13, 2024
1 parent 5522ad1 commit acd9082
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gitea_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions otc_services_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
import logging
import csv
import pathlib

logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit acd9082

Please sign in to comment.