Skip to content

Commit

Permalink
添加头部
Browse files Browse the repository at this point in the history
  • Loading branch information
elysias123 committed May 12, 2024
1 parent 7de1801 commit 8399553
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 20 deletions.
10 changes: 6 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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} 目录不存在!")
Expand All @@ -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:
Expand All @@ -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}")

Expand Down
2 changes: 1 addition & 1 deletion script/AdClose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "!"
2 changes: 1 addition & 1 deletion script/Adblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "!"
2 changes: 1 addition & 1 deletion script/Adguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "!"
2 changes: 1 addition & 1 deletion script/Clash.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "#"
2 changes: 1 addition & 1 deletion script/Mosdns_v5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "#"
2 changes: 1 addition & 1 deletion script/QuantumultX.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "#"
6 changes: 3 additions & 3 deletions script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
`Adguard.py`:

```python
["||xxx.com^","||xxx.cc^"], ".txt"
["||xxx.com^","||xxx.cc^"], ".txt", "!"
```
> **有两个返回值**
> **有三个返回值**
API:
- rule.domain_list(获取域名列表)
Expand All @@ -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", "#" # 返回处理后的列表和文件后缀名和文件注释符号
```
> 输出文件名=插件名
2 changes: 1 addition & 1 deletion script/RouterOS-Adlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "#"
2 changes: 1 addition & 1 deletion script/RouterOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "#"
2 changes: 1 addition & 1 deletion script/Singbox-regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def build(rule):
}

json_data = json.dumps(List, indent=2)
return [json_data], ".json"
return [json_data], ".json", "//"
2 changes: 1 addition & 1 deletion script/Singbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ def build(rule):
}

json_data = json.dumps(rule, indent=2)
return [json_data], ".json"
return [json_data], ".json", "//"
2 changes: 1 addition & 1 deletion script/Surge-DOMAIN-SET.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "#"
2 changes: 1 addition & 1 deletion script/Surge-RULE-SET.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "#"
2 changes: 1 addition & 1 deletion script/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "!"

0 comments on commit 8399553

Please sign in to comment.