Finished refactoring options 9 and 10

This commit is contained in:
doctor_dev 2025-05-30 19:38:04 +00:00
parent 19e582203b
commit 2a827c0b8b
No known key found for this signature in database
GPG key ID: F12F7F71CB84AEAA
2 changed files with 84 additions and 97 deletions

View file

@ -60,7 +60,7 @@ def IsXFTPServerValid(url: str) -> bool:
Returns True if URL is a valid SimpleX XFTP Server URL
False otherwise
"""
return conf.RecognizeSimplexType(url) == 'xftp'
return RecognizeSimplexType(url) == 'xftp'
# stub function
def IsSMPServerValid(url: str) -> bool:
@ -68,7 +68,7 @@ def IsSMPServerValid(url: str) -> bool:
Returns True if URL is a valid SimpleX SMP Server URL
False otherwise
"""
return conf.RecognizeSimplexType(url) == 'smp'
return RecognizeSimplexType(url) == 'smp'
def IsClearnetLinkValid(url: str) -> bool:
"""
@ -242,7 +242,7 @@ def IsNameValid(name: str) -> bool:
Check the parameter name only contains [a-zA-Z0-9] and is 64 chars long.
"""
try:
return bool(VALID_NAME_PATTERN.fullmatch(name.strip()))
return bool(conf.VALID_NAME_PATTERN.fullmatch(name.strip()))
except Exception:
return False
@ -278,10 +278,10 @@ def is_row_valid(row):
"""
try:
return (
IsUrlValid(row['Instance']) and
IsURLValid(row['Instance']) and
IsCategoryValid(row['Category']) and
IsNameValid(row['Name']) and
IsUrlValid(row['URL']) and
IsURLValid(row['URL']) and
IsStatusValid(row['Sensitive']) and
IsDescriptionValid(row['Description']) and
IsStatusValid(row['Status']) and
@ -339,6 +339,17 @@ def remove_duplications(df):
return df
def remove_cross_dataframe_replications(main_df, sub_df):
"""
remove replications from sub_df that exist in main_df
Parameters:
main_df (Dataframe): the dataframe to keep replications
sub_df (Dataframe): the dataframe to remove replications
Returns:
Dataframe: the main_df with removed duplications
Dataframe: the sub_df with removed duplications and removed replications
"""
try:
main_df = remove_duplications(main_df)
@ -350,7 +361,6 @@ def remove_cross_dataframe_replications(main_df, sub_df):
except Exception as err:
print_colors('[-] Removing cross dataframe duplications failed',is_error=True)
raise err #REMOVE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
return main_df, sub_df
@ -365,7 +375,7 @@ def save_local_verified_and_unverified(verified_df, unverified_df):
unverified_df (Dataframe): local unverified rows dataframe
Returns:
Dataframe: the combined dataframe will be returned
bool: True if successful, False if not
"""
try:
current_instance = get_current_instance() + '/'
@ -382,6 +392,32 @@ def save_local_verified_and_unverified(verified_df, unverified_df):
print_colors('[-] Saving verified and unverified failed',is_error=True)
return False
def save_local_participant_verified_and_unverified(verified_df, unverified_df, participant):
"""
saves the local verified and unverified of a participant
Parameters:
verified_df (Dataframe): local verified rows dataframe
unverified_df (Dataframe): local unverified rows dataframe
participant (str): participant's onion local path
Returns:
bool: True if successful, False if not
"""
try:
verified_df.to_csv(f'{participant}verified.csv', index=False)
unverified_df.to_csv(f'{participant}unverified.csv', index=False)
print_colors('[+] Verified and unverified saved successfully')
return True
except Exception as err:
print_colors('[-] Saving verified and unverified failed',is_error=True)
return False
###################### Getters/Generators ######################
def generate_participant_url(participant):
"""
@ -414,7 +450,7 @@ def get_participant_local_verified_and_unverified(participant):
reads the local verified csv and the local unverified csv of a participant
Parameters:
participant (str): participant's onion address/instance
participant (str): participant's local files path
Returns:
verified_df(Dataframe): verified.csv as dataframe
@ -422,25 +458,21 @@ def get_participant_local_verified_and_unverified(participant):
"""
try:
current_instance = get_current_instance() + '/'
try:
verified_df = pd.read_csv(f'{participant}verified.csv')
except FileNotFoundError:
print_colors("[-] File not found: verified.csv", is_error=True)
verified_df = pd.read_csv(f'{participant}verified.csv')
except FileNotFoundError:
print_colors("[-] File not found: verified.csv", is_error=True)
return pd.Dataframe(), pd.Dataframe()
try:
unverified_df = pd.read_csv(f'{participant}unverified.csv')
try:
unverified_df = pd.read_csv(f'{participant}unverified.csv')
except FileNotFoundError:
print_colors("[-] Participant File not found: unverified.csv", is_error=True)
except FileNotFoundError:
print_colors("[-] Participant File not found: unverified.csv", is_error=True)
return pd.Dataframe(), pd.Dataframe()
return verified_df, unverified_df
return verified_df, unverified_df
except Exception as err:
print_colors('[-] Failed reading the verified and unverified files',is_error=True)
return pd.DataFrame(), pd.DataFrame()
def get_official_participants():
"""