X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=fba%2Fhelpers%2Ftidyup.py;h=acd8bc655475bfc6cd4b472a0b0b1f53cd6edd54;hb=600b452ced0fbf1c9c9796cf5afed63a1baead5a;hp=ef027afcdfd20277b14c8dc25f944da3f0fae72d;hpb=295618ea79b35b321817ca807fad609461d69b56;p=fba.git diff --git a/fba/helpers/tidyup.py b/fba/helpers/tidyup.py index ef027af..acd8bc6 100644 --- a/fba/helpers/tidyup.py +++ b/fba/helpers/tidyup.py @@ -21,8 +21,9 @@ logger = logging.getLogger(__name__) def reason(string: str) -> str: logger.debug("string='%s' - CALLED!", string) + if not isinstance(string, str): - raise ValueError(f"Parameter string[]='{type(string)}' is not 'str'") + raise ValueError(f"Parameter string[]='{type(string)}' is not of type 'str'") # Strip string string = string.strip() @@ -32,11 +33,14 @@ def reason(string: str) -> str: def domain(string: str) -> str: logger.debug("string='%s' - CALLED!", string) + if not isinstance(string, str): - raise ValueError(f"Parameter string[]='{type(string)}' is not 'str'") + raise ValueError(f"Parameter string[]='{type(string)}' is not of type 'str'") + elif string == "": + raise ValueError("Parameter string is empty") # All lower-case and strip spaces out + last dot - string = string.lower().strip().rstrip(".") + string = string.lower().strip().rstrip(".").replace("..", ".") logger.debug("string='%s' - #1", string) # No port number @@ -56,7 +60,9 @@ def domain(string: str) -> str: string = string.split(":")[0] logger.debug("string='%s' - #5", string) - # No individual users in block lists + # Try to "detect" user profiles, not wanted here. Don't block single users + # in an instance block list! Everything personal can be solved in a + # personal block. string = re.sub(r"(.+)\@", "", string) logger.debug("string='%s' - #6", string) @@ -67,5 +73,10 @@ def domain(string: str) -> str: elif string.find("/tag/"): string = string.split("/tag/")[0] + # Some people have TLDs with this word on the end + logger.debug("string='%s' - #7", string) + if string.endswith("silence"): + string = string.split("silence")[0] + logger.debug("string='%s' - EXIT!", string) return string