-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathmerge_mermeroo_to_config_sources.py
More file actions
46 lines (37 loc) · 1.21 KB
/
merge_mermeroo_to_config_sources.py
File metadata and controls
46 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
import os
import json
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
MERMEROO_FILE = os.path.join(BASE_PATH, "mermeroo_only_new_for_mirror.txt")
CFG_FILE = os.path.join(BASE_PATH, "config_sources.json")
def load_lines(path):
if not os.path.exists(path):
print(f"{path} не найден")
return []
with open(path, "r", encoding="utf-8") as f:
return [l.strip() for l in f if l.strip()]
def main():
new_urls = load_lines(MERMEROO_FILE)
if os.path.exists(CFG_FILE):
with open(CFG_FILE, "r", encoding="utf-8") as f:
try:
data = json.load(f)
except Exception:
data = []
else:
data = []
if not isinstance(data, list):
data = []
known = set(data)
added = 0
for u in new_urls:
if u not in known:
data.append(u)
known.add(u)
added += 1
with open(CFG_FILE, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
print(f"Добавлено новых источников: {added}")
print(f"Всего в config_sources.json: {len(data)}")
if __name__ == "__main__":
main()