From 8399553a85bacb5c299b1858506f67a1ffd67366 Mon Sep 17 00:00:00 2001 From: heinu123 Date: Sun, 12 May 2024 19:32:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A4=B4=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 10 ++++++---- script/AdClose.py | 2 +- script/Adblock.py | 2 +- script/Adguard.py | 2 +- script/Clash.py | 2 +- script/Mosdns_v5.py | 2 +- script/QuantumultX.py | 2 +- script/README.md | 6 +++--- script/RouterOS-Adlist.py | 2 +- script/RouterOS.py | 2 +- script/Singbox-regex.py | 2 +- script/Singbox.py | 2 +- script/Surge-DOMAIN-SET.py | 2 +- script/Surge-RULE-SET.py | 2 +- script/hosts.py | 2 +- 15 files changed, 22 insertions(+), 20 deletions(-) diff --git a/main.py b/main.py index 5eb4029..67c025a 100755 --- a/main.py +++ b/main.py @@ -3,7 +3,6 @@ import json import importlib from datetime import datetime -global output, domain_file, domain_file, suffix_file, regex_file SCRIPT_PATH = os.path.join(os.getcwd(), "script") RULE_PATH = os.path.join(os.getcwd(), "rule") @@ -12,6 +11,8 @@ regex_file=RULE_PATH + "/domain_regex.txt" ip_file=RULE_PATH + "/ip.txt" ip6_file=RULE_PATH + "/ip6.txt" +current_time = datetime.now() +format_time = current_time.strftime("%Y-%m-%d") if not os.path.exists(OUT_PATH): print(f"{OUT_PATH} 目录不存在!") @@ -30,9 +31,10 @@ def __init__(self, domain_file, regex_file, ip_file, ip6_file): rule = RuleList(domain_file, regex_file, ip_file, ip6_file) -def WriteFile(name, text, suffix): +def WriteFile(name, text, suffix, comment): try: with open(OUT_PATH + "/AWAvenue-Ads-Rule-" + name + suffix, 'w', encoding="utf-8") as file: + file.write(f"{comment}Title: AWAvenue 秋风广告规则(AWAvenue-Ads-Rule)\n{comment}上次更新日期: {format_time}\n\n{comment}项目地址:https://github.com/TG-Twilight/AWAvenue-Ads-Rule\n\n{comment}如果需要在其它规则中混合此规则,请在您的规则显眼处注明本规则的出处,谢谢!\n{comment}加入Telegram群组 秋風がく山道 (@AWAvenueAdsChat) 与编写者交流,期待着您的到来!\n{comment}群组链接:https://t.me/AWAvenueAdsChat\n{comment}订阅Telegram频道 AWAvenue Ads Rule (@AWAvenueAdsRule) 获取最新公告,期待着您的订阅!\n{comment}频道链接:https://t.me/AWAvenueAdsRule\n\n{comment}This project is licensed under the Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) license.\n{comment}AD:\n{comment}倾城极速 - 畅游世界,高速互联!官网:https://wcnmdmht.lol/sb 官网2:https://panel.qc02.xyz\n") for line in text: file.write(line + "\n") except Exception as e: @@ -45,8 +47,8 @@ def RunScript(): full_module_name = f"script.{module_name}" try: module = importlib.import_module(full_module_name) - module_list, module_suffix = module.build(rule) - WriteFile(module_name, module_list, module_suffix) + module_list, module_suffix, module_comment = module.build(rule) + WriteFile(module_name, module_list, module_suffix, module_comment) except Exception as e: print(f"转换插件:{module_name}执行失败: {e}") diff --git a/script/AdClose.py b/script/AdClose.py index 5f67801..9cdf8b3 100755 --- a/script/AdClose.py +++ b/script/AdClose.py @@ -15,4 +15,4 @@ def format_regex(List): def build(rule): Adclose_list = format_domain(rule.domain_list) + format_regex(rule.regex_list) - return Adclose_list, ".txt" \ No newline at end of file + return Adclose_list, ".txt", "!" \ No newline at end of file diff --git a/script/Adblock.py b/script/Adblock.py index da92450..f6fd3a3 100755 --- a/script/Adblock.py +++ b/script/Adblock.py @@ -15,4 +15,4 @@ def format_regex(List): def build(rule): Adblock_list = format_domain(rule.domain_list) + format_regex(rule.regex_list) - return Adblock_list, ".txt" \ No newline at end of file + return Adblock_list, ".txt", "!" \ No newline at end of file diff --git a/script/Adguard.py b/script/Adguard.py index 5208758..ce05e39 100755 --- a/script/Adguard.py +++ b/script/Adguard.py @@ -15,4 +15,4 @@ def format_regex(List): def build(rule): Adguard_list = format_domain(rule.domain_list) + format_regex(rule.regex_list) - return Adguard_list, ".txt" \ No newline at end of file + return Adguard_list, ".txt", "!" \ No newline at end of file diff --git a/script/Clash.py b/script/Clash.py index 052962a..11d5d5f 100755 --- a/script/Clash.py +++ b/script/Clash.py @@ -22,4 +22,4 @@ def format_ip(List): def build(rule): clash_list = ["payload:"] + format_ip(rule.ip_list) + format_domain(rule.domain_list) + format_regex(rule.regex_list) - return clash_list, ".yaml" \ No newline at end of file + return clash_list, ".yaml", "#" \ No newline at end of file diff --git a/script/Mosdns_v5.py b/script/Mosdns_v5.py index 76a2a09..070f432 100644 --- a/script/Mosdns_v5.py +++ b/script/Mosdns_v5.py @@ -9,4 +9,4 @@ def format_domain(List): def build(rule): - return format_domain(rule.domain_list), ".txt" + return format_domain(rule.domain_list), ".txt", "#" diff --git a/script/QuantumultX.py b/script/QuantumultX.py index e7a46a0..d47423a 100755 --- a/script/QuantumultX.py +++ b/script/QuantumultX.py @@ -21,4 +21,4 @@ def format_ip(List): return ip def build(rule): - return format_ip(rule.ip_list) + format_domain(rule.domain_list) + format_regex(rule.regex_list), ".list" \ No newline at end of file + return format_ip(rule.ip_list) + format_domain(rule.domain_list) + format_regex(rule.regex_list), ".list", "#" \ No newline at end of file diff --git a/script/README.md b/script/README.md index b8aec67..3ba5ee3 100755 --- a/script/README.md +++ b/script/README.md @@ -7,9 +7,9 @@ `Adguard.py`: ```python -["||xxx.com^","||xxx.cc^"], ".txt" +["||xxx.com^","||xxx.cc^"], ".txt", "!" ``` -> **有两个返回值** +> **有三个返回值** API: - rule.domain_list(获取域名列表) @@ -23,6 +23,6 @@ API: # 主函数并且引入rule(对象) def build(rule): list = rule.domain_list + rule.regex_list + rule.ip_list - return list, ".yaml" # 返回处理后的列表和文件后缀名 + return list, ".yaml", "#" # 返回处理后的列表和文件后缀名和文件注释符号 ``` > 输出文件名=插件名 \ No newline at end of file diff --git a/script/RouterOS-Adlist.py b/script/RouterOS-Adlist.py index a3d8326..bc51af5 100755 --- a/script/RouterOS-Adlist.py +++ b/script/RouterOS-Adlist.py @@ -9,4 +9,4 @@ def format_domain(List): def build(rule): - return format_domain(rule.domain_list), ".txt" \ No newline at end of file + return format_domain(rule.domain_list), ".txt", "#" \ No newline at end of file diff --git a/script/RouterOS.py b/script/RouterOS.py index 723587c..f0d732b 100755 --- a/script/RouterOS.py +++ b/script/RouterOS.py @@ -8,4 +8,4 @@ def format_domain(List): return domain def build(rule): - return format_domain(rule.regex_list), ".txt" + return format_domain(rule.regex_list), ".txt", "#" diff --git a/script/Singbox-regex.py b/script/Singbox-regex.py index 5b344c8..c127e94 100755 --- a/script/Singbox-regex.py +++ b/script/Singbox-regex.py @@ -30,4 +30,4 @@ def build(rule): } json_data = json.dumps(List, indent=2) - return [json_data], ".json" \ No newline at end of file + return [json_data], ".json", "//" \ No newline at end of file diff --git a/script/Singbox.py b/script/Singbox.py index e4e89d5..5cba21f 100755 --- a/script/Singbox.py +++ b/script/Singbox.py @@ -21,4 +21,4 @@ def build(rule): } json_data = json.dumps(rule, indent=2) - return [json_data], ".json" \ No newline at end of file + return [json_data], ".json", "//" \ No newline at end of file diff --git a/script/Surge-DOMAIN-SET.py b/script/Surge-DOMAIN-SET.py index b7121d9..a4deec7 100755 --- a/script/Surge-DOMAIN-SET.py +++ b/script/Surge-DOMAIN-SET.py @@ -7,4 +7,4 @@ def format_domain(List): def build(rule): surge_list = format_domain(rule.domain_list) - return surge_list, ".list" \ No newline at end of file + return surge_list, ".list", "#" \ No newline at end of file diff --git a/script/Surge-RULE-SET.py b/script/Surge-RULE-SET.py index 4704dde..29090a2 100755 --- a/script/Surge-RULE-SET.py +++ b/script/Surge-RULE-SET.py @@ -20,4 +20,4 @@ def format_ip(List): return ip def build(rule): - return format_ip(rule.ip_list) + format_domain(rule.domain_list) + format_regex(rule.regex_list), ".list" \ No newline at end of file + return format_ip(rule.ip_list) + format_domain(rule.domain_list) + format_regex(rule.regex_list), ".list", "#" \ No newline at end of file diff --git a/script/hosts.py b/script/hosts.py index 741913e..e42cdb1 100755 --- a/script/hosts.py +++ b/script/hosts.py @@ -8,4 +8,4 @@ def format_domain(List): def build(rule): - return format_domain(rule.domain_list), ".txt" \ No newline at end of file + return format_domain(rule.domain_list), ".txt", "!" \ No newline at end of file