From 50f6a637cd1d73ee8430d8541f04dc6a098470f2 Mon Sep 17 00:00:00 2001 From: doctor_dev Date: Tue, 10 Jun 2025 06:22:26 +0000 Subject: [PATCH] fixed option 4 removing local instance rows --- scripts/logic/options.py | 8 ++++---- scripts/utils.py | 31 +++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/scripts/logic/options.py b/scripts/logic/options.py index 9cd3be5..fe8cc47 100644 --- a/scripts/logic/options.py +++ b/scripts/logic/options.py @@ -16,10 +16,10 @@ def run_option_4(): utils.print_colors('[+] Syncing official webrings to local webrings') - webring_df = utils.get_local_webring_participants() - current_instance = utils.get_current_instance() + webring_df = utils.get_local_webring_participants(current_instance) + utils.print_colors('[+] Reading local blacklist and sensitive words') local_blacklist_df = utils.get_local_blacklist() local_sensitive_df = utils.get_local_sensitive() @@ -28,8 +28,8 @@ def run_option_4(): local_verified_df, local_unverified_df = utils.get_local_verified_and_unverified() #Remove all rows - local_unverified_df = local_unverified_df[0:0] - local_verified_df = local_verified_df[0:0] + local_unverified_df = utils.renew_csv(local_unverified_df, current_instance) + local_verified_df = utils.renew_csv(local_verified_df, current_instance) for participant in webring_df.itertuples(index=False, name='columns'): # Check if the participant is my instance diff --git a/scripts/utils.py b/scripts/utils.py index 790be16..497ed19 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -305,6 +305,26 @@ def is_row_valid(row): ###################### General ###################### +def renew_csv(df, participant_url): + """ + Removes all rows that are not generated by the local instance + + Parameters + ---------- + df : pd.DataFrame + Dataframe we want to renew + participant_url : str + the instance url + + Returns: + -------- + pd.DataFrame + The renewed dataframe + """ + + return df[df['Instance'] == participant_url] + + def merge_verification_df(receiving_df, merging_df): """ Merges 2 dataframes of type verified or unverified (do not merge duplications by name or url) @@ -775,10 +795,15 @@ def get_local_verified_and_unverified(): return pd.DataFrame(), pd.DataFrame() -def get_local_webring_participants(): +def get_local_webring_participants(current_instance): """ Make sure the official participants are registered in the webring csv file + Parameters + ---------- + current_instance : str + The current local instance url + Returns ------- pd.DataFrame @@ -792,7 +817,9 @@ def get_local_webring_participants(): missing_participants = set(get_official_participants()) - set(webring_df['URL']) for participant in missing_participants: - new_row = [{'Name': '','URL': participant,'Description': '','Trusted': 'NO','Status': '','Score': ''}] + if participant == current_instance: + continue + new_row = [{'Name': '','URL': participant,'Description': '','Trusted': 'NO','Status': '','Score': '', 'Blacklisted': 'NO'}] webring_df = pd.concat([webring_df, pd.DataFrame(new_row)], ignore_index=True) save_dataframe(webring_df, conf.LOCAL_DIR + conf.WEBRING_CSV_FILE)