From 13b57bb8470a4e1c11fa9b5f0fcc15cb24f4d681 Mon Sep 17 00:00:00 2001 From: ElonJunior Date: Sat, 24 Aug 2024 04:31:41 +0800 Subject: [PATCH] SOURCE_REPLACE_DICT for oisd --- resouces/convert_adguard.py | 24 ++++++++++++------------ resouces/helper/helper.py | 6 +++++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/resouces/convert_adguard.py b/resouces/convert_adguard.py index 0a55a417..73f92349 100755 --- a/resouces/convert_adguard.py +++ b/resouces/convert_adguard.py @@ -26,14 +26,14 @@ from helper.helper import ( SING_BOX_EXEC_PATH = None ADGUARD_CONFIG_FILTER_LIST = [ - { - 'name': 'AdGuardFilter', - 'source': 'https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/configuration.json', - }, - { - 'name': 'PopupFilter', - 'source': 'https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/configuration_popup_filter.json', - }, + # { + # 'name': 'AdGuardFilter', + # 'source': 'https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/configuration.json', + # }, + # { + # 'name': 'PopupFilter', + # 'source': 'https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/configuration_popup_filter.json', + # }, { 'name': 'ppfeuferFilter', 'source': 'https://raw.githubusercontent.com/ppfeufer/adguard-filter-list/master/hostlist-compiler-config.json', @@ -42,7 +42,7 @@ ADGUARD_CONFIG_FILTER_LIST = [ SOURCE_REPLACE_DICT = { # # Get OISD list, since the HostlistCompiler can't fetch it for whatever reason » https://github.com/AdguardTeam/HostlistCompiler/issues/58 - '../oisd.txt': 'https://big.oisd.nl/', + "../oisd.txt": "https://big.oisd.nl/", } @@ -100,8 +100,6 @@ def main(out_path: str = None): def compile_filterlist(out_path: str, item: dict): source = item['source'] - if source in SOURCE_REPLACE_DICT: - source = SOURCE_REPLACE_DICT[source] name = correct_name(item['name']) out_path2 = os.path.join(out_path, name) @@ -133,9 +131,11 @@ def compile_filterlist(out_path: str, item: dict): def compile_filterone(out_path: str, item: dict) -> bool: - name = correct_name(item['name']) source = item['source'] + if source in SOURCE_REPLACE_DICT: + source = SOURCE_REPLACE_DICT[source] + name = correct_name(item['name']) debug_log(f"\n\tdownloading [ {name} ] => {source}") content = get_url_content(source) if content is None: diff --git a/resouces/helper/helper.py b/resouces/helper/helper.py index a1494b8e..e89b41f6 100644 --- a/resouces/helper/helper.py +++ b/resouces/helper/helper.py @@ -59,13 +59,16 @@ def correct_name(text: str) -> str: # Apply the replacements replaced_text = ''.join(replacements.get(c, c) for c in text) - # Collapse consecutive "-" into a single "-" + # Collapse consecutive "-" or "_" into a single "_" collapsed_text = re.sub(r'-+', '-', replaced_text) collapsed_text = re.sub(r'_+', '_', collapsed_text) # Remove trailing "-" or "_" final_text = re.sub(r'[-_]+$', '', collapsed_text) + # Replace "-_" and "_-" with "_" + final_text = re.sub(r'-_|_-', '_', final_text) + return final_text @@ -78,6 +81,7 @@ def remove_ansi_escape_codes(text: str) -> str: if __name__ == '__main__': # text = "example string//with spaces---and////slashes" text = 'uBlock-filters-–-Resource-abuse-' + text = 'Dandelion-Sprouts-Anti-Malware-List-_for-AdGuard-Home-and-for-AdGuard-for-Android_Windows-DNS-filtering' print(correct_name(text)) # text = '\x1b[36mINFO\x1b[0m[0000] parsed rules: 778/1450'