添加头部

This commit is contained in:
heinu123 2024-05-12 19:32:14 +08:00
parent 7de1801a4a
commit 8399553a85
15 changed files with 22 additions and 20 deletions

10
main.py
View File

@ -3,7 +3,6 @@ import sys
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 @@ domain_file=RULE_PATH + "/domain.txt"
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 @@ class RuleList:
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 官网2https://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}")

View File

@ -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"
return Adclose_list, ".txt", "!"

View File

@ -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"
return Adblock_list, ".txt", "!"

View File

@ -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"
return Adguard_list, ".txt", "!"

View File

@ -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"
return clash_list, ".yaml", "#"

View File

@ -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", "#"

View File

@ -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"
return format_ip(rule.ip_list) + format_domain(rule.domain_list) + format_regex(rule.regex_list), ".list", "#"

View File

@ -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", "#" # 返回处理后的列表和文件后缀名和文件注释符号
```
> 输出文件名=插件名

View File

@ -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", "#"

View File

@ -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", "#"

View File

@ -30,4 +30,4 @@ def build(rule):
}
json_data = json.dumps(List, indent=2)
return [json_data], ".json"
return [json_data], ".json", "//"

View File

@ -21,4 +21,4 @@ def build(rule):
}
json_data = json.dumps(rule, indent=2)
return [json_data], ".json"
return [json_data], ".json", "//"

View File

@ -7,4 +7,4 @@ def format_domain(List):
def build(rule):
surge_list = format_domain(rule.domain_list)
return surge_list, ".list"
return surge_list, ".list", "#"

View File

@ -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"
return format_ip(rule.ip_list) + format_domain(rule.domain_list) + format_regex(rule.regex_list), ".list", "#"

View File

@ -8,4 +8,4 @@ def format_domain(List):
def build(rule):
return format_domain(rule.domain_list), ".txt"
return format_domain(rule.domain_list), ".txt", "!"