Skip to content

Commit

Permalink
Add snippets!
Browse files Browse the repository at this point in the history
  • Loading branch information
peasoft committed Jul 3, 2023
1 parent ceac2e2 commit c46975f
Show file tree
Hide file tree
Showing 16 changed files with 206,154 additions and 108,769 deletions.
1 change: 1 addition & 0 deletions .github/workflows/fetch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
git config --local user.name "GitHub Actions"
git pull origin master
git add list*
git add snippets/
git commit -m "$(date '+%Y-%m-%d %H:%M:%S') 抓取节点"
- name: 推送更改
uses: ad-m/github-push-action@master
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__/
local*
_*
_*
!_config*
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### 注意:原有的链接 1 出现过问题,我们在它前面添加了新的链接 1 并下移了原有链接。我们建议您将订阅链接改为新的加速链接 1。加速链接 3/4 含有缓存,可能不是最新,且访问速度没有链接 1 快。

我们新增了 `snippets` 文件夹来存放从 `list.yml` 中拆分出的配置片段,用于将本项目提供的一些配置整合到你自己的配置中。
此项目现已添加“反 996 许可证”,请各位使用者**不要违法违规要求别人加班,自觉遵守《中华人民共和国劳动法》及其它法律法规**

## 使用方法
Expand Down
41 changes: 33 additions & 8 deletions fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def b64decodes_safe(s):

FETCH_TIMEOUT = (6, 5)

DEBUG_NO_NODES = os.path.exists("local_NO_NODES") # !!! JUST FOR DEBUGING !!!
# !!! JUST FOR DEBUGING !!!
DEBUG_NO_NODES = os.path.exists("local_NO_NODES")
DEBUG_NO_ADBLOCK = os.path.exists("local_NO_ADBLOCK")

class UnsupportedType(Exception): pass
class NotANode(Exception): pass
Expand Down Expand Up @@ -534,7 +536,7 @@ def raw2fastly(url: str) -> str:
return url

def main():
global exc_queue, FETCH_TIMEOUT
global exc_queue, FETCH_TIMEOUT, ABFURLS
from dynamic import AUTOURLS, AUTOFETCH, set_dynamic_globals
sources = open("sources.list", encoding="utf-8").read().strip().splitlines()
if DEBUG_NO_NODES:
Expand Down Expand Up @@ -669,6 +671,10 @@ def main():

with open("config.yml", encoding="utf-8") as f:
conf: Dict[str, Any] = yaml.full_load(f)
if DEBUG_NO_ADBLOCK:
# !!! JUST FOR DEBUGING !!!
print("!!! 警告:您已关闭对 Adblock 规则的抓取 !!!")
ABFURLS = ()
print("正在解析 Adblock 列表... ", end='', flush=True)
blocked: Set[str] = set()
for url in ABFURLS:
Expand Down Expand Up @@ -700,10 +706,9 @@ def main():
print(f"共有 {len(adblock_rules)} 条规则")

print("正在写出 Clash 订阅...")
rules = conf['rules']
rules2 = {}
rules2: Dict[str, str] = {}
match_rule = None
for rule in rules:
for rule in conf['rules']:
tmp = rule.strip().split(',')
if len(tmp) == 2 and tmp[0] == 'MATCH':
match_rule = rule
Expand All @@ -717,8 +722,8 @@ def main():
k = rtype+','+rargument
if k not in rules2:
rules2[k] = rpolicy
rules3 = [','.join(_) for _ in rules2.items()]+[match_rule]
conf['rules'] = adblock_rules + rules3
rules = [','.join(_) for _ in rules2.items()]+[match_rule]
conf['rules'] = adblock_rules + rules
conf['proxies'] = []
names_clash: Set[str] = set()
for p in merged:
Expand All @@ -732,7 +737,27 @@ def main():
with open("list.yml", 'w', encoding="utf-8") as f:
f.write(yaml.dump(conf, allow_unicode=True).replace('!!str ',''))

# print("正在写出配置片段...")
print("正在写出配置片段...")
with open("snippets/nodes.yml", 'w', encoding="utf-8") as f:
yaml.dump({'proxies': conf['proxies']}, f, allow_unicode=True)
try:
with open("snippets/_config.yml", encoding="utf-8") as f:
snip_conf: Dict[Any] = yaml.full_load(f)
except (OSError, yaml.error.YAMLError):
print("配置文件读取失败:")
traceback.print_exc()
else:
name_map: Dict[str, str] = snip_conf['name-map']
snippets: Dict[str, List[str]] = {}
for rpolicy in name_map.values(): snippets[rpolicy] = []
for rule, rpolicy in rules2.items():
if ',' in rpolicy: rpolicy = rpolicy.split(',')[0]
if rpolicy in name_map:
snippets[name_map[rpolicy]].append(rule)
snippets['ADBLOCK'] = [','.join(_.split(',')[:-1]) for _ in adblock_rules]
for name, payload in snippets.items():
with open("snippets/"+name+".yml", 'w', encoding="utf-8") as f:
yaml.dump({'payload': payload}, f, allow_unicode=True)

print("正在写出统计信息...")
out = "序号,链接,节点数\n"
Expand Down
1 change: 0 additions & 1 deletion list.txt

Large diffs are not rendered by default.

Loading

0 comments on commit c46975f

Please sign in to comment.