mirror of
https://github.com/TG-Twilight/AWAvenue-Ads-Rule.git
synced 2025-11-04 14:49:47 +08:00
update Title
This commit is contained in:
parent
fdd0c97a8f
commit
f5ef7d28cf
26
main.py
26
main.py
@ -3,7 +3,7 @@ import sys
|
|||||||
import json
|
import json
|
||||||
import importlib
|
import importlib
|
||||||
import subprocess
|
import subprocess
|
||||||
from datetime import datetime
|
import datetime
|
||||||
|
|
||||||
SCRIPT_PATH = os.path.join(os.getcwd(), "script")
|
SCRIPT_PATH = os.path.join(os.getcwd(), "script")
|
||||||
RULE_PATH = os.path.join(os.getcwd(), "rule")
|
RULE_PATH = os.path.join(os.getcwd(), "rule")
|
||||||
@ -12,8 +12,8 @@ domain_file=RULE_PATH + "/domain.txt"
|
|||||||
regex_file=RULE_PATH + "/domain_regex.txt"
|
regex_file=RULE_PATH + "/domain_regex.txt"
|
||||||
ip_file=RULE_PATH + "/ip.txt"
|
ip_file=RULE_PATH + "/ip.txt"
|
||||||
ip6_file=RULE_PATH + "/ip6.txt"
|
ip6_file=RULE_PATH + "/ip6.txt"
|
||||||
current_time = datetime.now()
|
current_time = datetime.datetime.now(datetime.timezone.utc)
|
||||||
format_time = current_time.strftime("%Y-%m-%d")
|
format_time = current_time.isoformat()
|
||||||
process = subprocess.Popen('git tag | tail -1', stdout=subprocess.PIPE, shell=True)
|
process = subprocess.Popen('git tag | tail -1', stdout=subprocess.PIPE, shell=True)
|
||||||
output, error = process.communicate()
|
output, error = process.communicate()
|
||||||
tag = output.decode().strip()
|
tag = output.decode().strip()
|
||||||
@ -22,6 +22,7 @@ if not os.path.exists(OUT_PATH):
|
|||||||
print(f"{OUT_PATH} 目录不存在!")
|
print(f"{OUT_PATH} 目录不存在!")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
class RuleList:
|
class RuleList:
|
||||||
def __init__(self, domain_file, regex_file, ip_file, ip6_file):
|
def __init__(self, domain_file, regex_file, ip_file, ip6_file):
|
||||||
with open(domain_file, 'r') as file:
|
with open(domain_file, 'r') as file:
|
||||||
@ -40,10 +41,21 @@ class RuleList:
|
|||||||
|
|
||||||
rule = RuleList(domain_file, regex_file, ip_file, ip6_file)
|
rule = RuleList(domain_file, regex_file, ip_file, ip6_file)
|
||||||
|
|
||||||
def WriteFile(name, text, suffix, comment):
|
def WriteFile(name, text, suffix, comment, module_total):
|
||||||
try:
|
try:
|
||||||
with open(OUT_PATH + "/AWAvenue-Ads-Rule-" + name + suffix, 'w', encoding="utf-8") as file:
|
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\n{comment}版本号: {tag}\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\n{comment}AD:\n{comment}倾城极速 - 畅游世界,高速互联!官网:https://panel.qqcjs.top 官网2:https://n3b53vrt.wcnmdmht.biz\n\n\n")
|
title = f"""{comment}Title: AWAvenue Ads Rule
|
||||||
|
{comment}Last modified: {format_time}
|
||||||
|
{comment}--------------------------------------
|
||||||
|
{comment}Total lines: {module_total}
|
||||||
|
{comment}Version: 1.5.0-release-Patch-2
|
||||||
|
|
||||||
|
{comment}Homepage: https://github.com/TG-Twilight/AWAvenue-Ads-Rule
|
||||||
|
{comment}License: https://github.com/TG-Twilight/AWAvenue-Ads-Rule/blob/main/LICENSE
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
file.write(title)
|
||||||
for line in text:
|
for line in text:
|
||||||
file.write(line + "\n")
|
file.write(line + "\n")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -56,8 +68,8 @@ def RunScript():
|
|||||||
full_module_name = f"script.{module_name}"
|
full_module_name = f"script.{module_name}"
|
||||||
try:
|
try:
|
||||||
module = importlib.import_module(full_module_name)
|
module = importlib.import_module(full_module_name)
|
||||||
module_list, module_suffix, module_comment = module.build(rule)
|
module_list, module_suffix, module_comment, module_total = module.build(rule)
|
||||||
WriteFile(module_name, module_list, module_suffix, module_comment)
|
WriteFile(module_name, module_list, module_suffix, module_comment, str(module_total))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"转换插件:{module_name}执行失败: {e}")
|
print(f"转换插件:{module_name}执行失败: {e}")
|
||||||
|
|
||||||
|
|||||||
@ -15,4 +15,4 @@ def format_regex(List):
|
|||||||
|
|
||||||
def build(rule):
|
def build(rule):
|
||||||
Adclose_list = format_domain(rule.domain_list) + format_regex(rule.regex_list)
|
Adclose_list = format_domain(rule.domain_list) + format_regex(rule.regex_list)
|
||||||
return Adclose_list, ".txt", "!"
|
return Adclose_list, ".txt", "!", len(Adclose_list)
|
||||||
@ -15,4 +15,4 @@ def format_regex(List):
|
|||||||
|
|
||||||
def build(rule):
|
def build(rule):
|
||||||
Adblock_list = format_domain(rule.domain_list) + format_regex(rule.regex_list)
|
Adblock_list = format_domain(rule.domain_list) + format_regex(rule.regex_list)
|
||||||
return Adblock_list, ".txt", "!"
|
return Adblock_list, ".txt", "!", len(Adblock_list)
|
||||||
@ -15,4 +15,4 @@ def format_regex(List):
|
|||||||
|
|
||||||
def build(rule):
|
def build(rule):
|
||||||
Adguard_list = format_domain(rule.domain_list) + format_regex(rule.regex_list)
|
Adguard_list = format_domain(rule.domain_list) + format_regex(rule.regex_list)
|
||||||
return Adguard_list, ".txt", "!"
|
return Adguard_list, ".txt", "!", len(Adguard_list)
|
||||||
@ -22,4 +22,4 @@ def format_ip(List):
|
|||||||
|
|
||||||
def build(rule):
|
def build(rule):
|
||||||
clash_list = ["payload:"] + format_ip(rule.ip_list) + format_domain(rule.domain_list) + format_regex(rule.regex_list)
|
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", "#", len(clash_list)
|
||||||
@ -16,4 +16,4 @@ def format_regex(List):
|
|||||||
|
|
||||||
def build(rule):
|
def build(rule):
|
||||||
clash_list = ["payload:"] + format_domain(rule.domain_list) + format_regex(rule.regex_list)
|
clash_list = ["payload:"] + format_domain(rule.domain_list) + format_regex(rule.regex_list)
|
||||||
return clash_list, ".yaml", "#"
|
return clash_list, ".yaml", "#", len(clash_list)
|
||||||
|
|||||||
@ -9,4 +9,4 @@ def format_domain(List):
|
|||||||
|
|
||||||
|
|
||||||
def build(rule):
|
def build(rule):
|
||||||
return format_domain(rule.domain_list), ".txt", "#"
|
return format_domain(rule.domain_list), ".txt", "#", len(rule.domain_list)
|
||||||
|
|||||||
@ -21,4 +21,5 @@ def format_ip(List):
|
|||||||
return ip
|
return ip
|
||||||
|
|
||||||
def build(rule):
|
def build(rule):
|
||||||
return format_ip(rule.ip_list) + format_domain(rule.domain_list) + format_regex(rule.regex_list), ".list", "#"
|
quantumultx_list = format_ip(rule.ip_list) + format_domain(rule.domain_list) + format_regex(rule.regex_list)
|
||||||
|
return quantumultx_list, ".list", "#", len(quantumultx_list)
|
||||||
@ -7,22 +7,47 @@
|
|||||||
`Adguard.py`:
|
`Adguard.py`:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
["||xxx.com^","||xxx.cc^"], ".txt", "!"
|
["||xxx.com^","||xxx.cc^"], ".txt", "!", xxx
|
||||||
```
|
```
|
||||||
> **有三个返回值**
|
|
||||||
|
> 处理后的域名列表(list), 文件后缀名(string), 注释符号(string), 规则数量(int|string)
|
||||||
|
|
||||||
API:
|
API:
|
||||||
- rule.domain_list(获取域名列表)
|
- rule.domain_list(获取域名列表)
|
||||||
- rule.regex_list(获取正则表达式的域名列表)
|
- rule.regex_list(获取正则表达式的域名列表)
|
||||||
- rule.ip_list(获取ip列表)
|
- rule.ip_list(获取ip列表)
|
||||||
|
- rule.ip6_list(获取ipv6列表)
|
||||||
|
|
||||||
> 所有变量均为列表 无需读取文件
|
> 所有变量均为列表 无需读取文件
|
||||||
|
|
||||||
模板:
|
模板:
|
||||||
```
|
```python
|
||||||
# 主函数并且引入rule(对象)
|
|
||||||
def build(rule):
|
def format_domain(List): # 转换域名规则
|
||||||
list = rule.domain_list + rule.regex_list + rule.ip_list
|
domain = []
|
||||||
return list, ".yaml", "#" # 返回处理后的列表和文件后缀名和文件注释符号
|
for line in List:
|
||||||
|
domain_lines = f" - DOMAIN,{line.strip()}"
|
||||||
|
domain.append(domain_lines)
|
||||||
|
return domain
|
||||||
|
|
||||||
|
def format_regex(List): # 转换正则表达式规则
|
||||||
|
regex = []
|
||||||
|
for line in List:
|
||||||
|
regex_lines = f" - DOMAIN-REGEX,'{line.strip()}'"
|
||||||
|
regex.append(regex_lines)
|
||||||
|
return regex
|
||||||
|
|
||||||
|
def format_ip(List): # 转换ip列表
|
||||||
|
ip = []
|
||||||
|
for line in List:
|
||||||
|
ip_lines = f" - IP-CIDR,{line.strip()}"
|
||||||
|
ip.append(ip_lines)
|
||||||
|
return ip
|
||||||
|
|
||||||
|
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", "#", len(clash_list)
|
||||||
|
#
|
||||||
|
|
||||||
```
|
```
|
||||||
> 输出文件名=插件名
|
> 输出文件名=插件名
|
||||||
@ -9,4 +9,4 @@ def format_domain(List):
|
|||||||
|
|
||||||
|
|
||||||
def build(rule):
|
def build(rule):
|
||||||
return format_domain(rule.domain_list), ".txt", "#"
|
return format_domain(rule.domain_list), ".txt", "#", len(rule.domain_list)
|
||||||
@ -8,4 +8,4 @@ def format_domain(List):
|
|||||||
return domain
|
return domain
|
||||||
|
|
||||||
def build(rule):
|
def build(rule):
|
||||||
return format_domain(rule.regex_list), ".txt", "#"
|
return format_domain(rule.regex_list), ".txt", "#", len(rule.regex_list)
|
||||||
|
|||||||
@ -29,5 +29,5 @@ def build(rule):
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
json_data = json.dumps(List, indent=2)
|
json_data = [json.dumps(List, indent=2)]
|
||||||
return [json_data], ".json", "//"
|
return json_data, ".json", "//", len(json_data)
|
||||||
@ -20,5 +20,5 @@ def build(rule):
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
json_data = json.dumps(rule, indent=2)
|
json_data = [json.dumps(rule, indent=2)]
|
||||||
return [json_data], ".json", "//"
|
return json_data, ".json", "//", len(json_data)
|
||||||
@ -20,4 +20,5 @@ def format_ip(List):
|
|||||||
return ip
|
return ip
|
||||||
|
|
||||||
def build(rule):
|
def build(rule):
|
||||||
return format_ip(rule.ip_list) + format_domain(rule.domain_list) + format_regex(rule.regex_list), ".list", "#"
|
surge_list = format_ip(rule.ip_list) + format_domain(rule.domain_list) + format_regex(rule.regex_list)
|
||||||
|
return surge_list, ".list", "#", len(surge_list)
|
||||||
@ -7,4 +7,4 @@ def format_domain(List):
|
|||||||
|
|
||||||
def build(rule):
|
def build(rule):
|
||||||
surge_list = format_domain(rule.domain_list)
|
surge_list = format_domain(rule.domain_list)
|
||||||
return surge_list, ".list", "#"
|
return surge_list, ".list", "#", len(surge_list)
|
||||||
@ -8,4 +8,4 @@ def format_domain(List):
|
|||||||
|
|
||||||
|
|
||||||
def build(rule):
|
def build(rule):
|
||||||
return format_domain(rule.domain_list), ".txt", "!"
|
return format_domain(rule.domain_list), ".txt", "!", len(rule.domain_list)
|
||||||
Loading…
Reference in New Issue
Block a user