FINished adding the trusted and the refactoring of 6

This commit is contained in:
doctor_dev 2025-06-03 16:58:03 +00:00
parent 8b0ba4833f
commit 14231fff92
No known key found for this signature in database
GPG key ID: F12F7F71CB84AEAA
5 changed files with 631 additions and 321 deletions

View file

@ -7,11 +7,15 @@ def download_participant_data(participant):
"""
Downloads the participants csv files and banner
Parameters:
participant (str): The url of the webring participant.
Parameters
----------
participant : str
The url of the webring participant.
Returns:
Boolean: True if all files downloaded, False if any of them failed
Returns
-------
Boolean
True if all files downloaded, False if any of them failed
"""
try:
@ -44,28 +48,34 @@ def download_participant_data(participant):
utils.print_colors(f"[+] Downloaded webring {participant} csv files and banner")
except Exception as err:
print_colors("[-] Downloading webring participant's files failed.", is_error=True)
utils.print_colors("[-] Downloading webring participant's files failed.", is_error=True)
def clean_csv(df, blacklist):
"""
Cleans duplications and blacklisted rows
Parameters:
df (dataframe): The dataframe we want to clean.
blacklist (list): The blacklisted words.
Parameters
----------
df pd.DataFrame
The dataframe we want to clean.
blacklist : list
The blacklisted words.
Returns:
Dataframe: Cleaned dataframe.
Returns
-------
pd.DataFrame
Cleaned dataframe.
"""
try:
if not df.empty:
df = utils.remove_duplications(df)
df = df[~df.apply(lambda row: any(word in str(value) for word in blacklist for value in row), axis=1)]
if not df.empty:
df = df[df.apply(utils.is_row_valid, axis=1)]
except Exception as err:
print_colors("[-] cleaning dataframe failed", is_error=True)
@ -75,12 +85,17 @@ def mark_sensitive(df, sensitive_list):
"""
Marks rows as sensitive
Parameters:
df (dataframe): The dataframe we want to mark.
sensitive (list): The sensitive words.
Parameters
----------
df : pd.DataFrame
The dataframe we want to mark.
sensitive : list
The sensitive words.
Returns:
Dataframe: Marked dataframe.
Returns
-------
pd.DataFrame
Marked dataframe.
"""
try:
@ -91,6 +106,72 @@ def mark_sensitive(df, sensitive_list):
df.loc[~sensitive_rows, 'Sensitive'] = 'NO'
except Exception as err:
print_colors("[-] MArking sensitive words failed.", is_error=True)
print_colors("[-] Marking sensitive words failed.", is_error=True)
return df
return df
def mark_webring_participant_trusted(webring_df, participant_id, trustworthy):
"""
Marks a webring to be trusted or not
Parameters
----------
webring_df : pd.DataFrame
dataframe of all the webring participants
participant_id : int
the index of the participant
trustworthy : bool
is the participant trustworthy or not
Returns
-------
pd.DataFrame
Marked webring dataframe with trust/untrust.
"""
try:
webring_df.iloc[participant_id, webring_df.columns.get_loc('Trusted')] = "YES" if trustworthy else "NO"
except Exception as err:
utils.print_colors("[-] Trusting or untrusting a webring participant failed", is_error = True)
return webring_df
def mark_webring_participant_blacklist(webring_df, participant_instance, participant_id, blacklisted):
"""
Marks a webring to be blacklisted or not
Parameters
----------
webring_df : pd.DataFrame
dataframe of all the webring participants
participant_id :int
the index of the participant
blacklisted : bool
is the participant set to be blacklisted or not
Returns
-------
pd.DataFrame
Marked webring dataframe with blacklist/unblacklist.
"""
try:
if blacklisted:
webring_df.iloc[participant_id, webring_df.columns.get_loc('Blacklisted')] = "YES"
utils.print_colors(f'[+] Adding new word to blacklist')
local_blacklist_df = utils.add_word_to_blacklist(participant_instance)
else:
webring_df.iloc[participant_id, webring_df.columns.get_loc('Blacklisted')] = "NO"
utils.print_colors(f'[+] Removing word from blacklist')
local_blacklist_df = utils.remove_word_from_blacklist(participant_instance)
except Exception as err:
utils.print_colors("[-] Blacklisting or unblacklisting a webring participlant failed", is_error = True)
raise err
return webring_df