-
Notifications
You must be signed in to change notification settings - Fork 394
Expand file tree
/
Copy pathmain.py
More file actions
61 lines (47 loc) · 1.62 KB
/
Copy pathmain.py
File metadata and controls
61 lines (47 loc) · 1.62 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
"""FreeNodeSpider CLI — AI-powered proxy node crawler.
Usage:
python main.py # run all sites
python main.py clashmeta # run single site
python main.py --help # show usage
"""
import argparse
import asyncio
import logging
import sys
from dotenv import load_dotenv
from src.config import load_config, save_config
from src.scheduler import Scheduler
# Windows console (GBK) can't encode flag emojis in summary output.
# Force UTF-8 with replacement chars so prints don't crash.
try:
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
except Exception:
pass
# Surface LLM warnings/errors (provider failures, model not found).
logging.basicConfig(level=logging.INFO, format="%(levelname)s %(message)s")
load_dotenv()
sys.path.insert(0, ".")
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="FreeNodeSpider — AI-powered proxy node crawler",
)
parser.add_argument(
"target",
nargs="?",
default=None,
help="Site name to process (default: all sites in config)",
)
return parser.parse_args()
async def main():
args = parse_args()
config = load_config()
scheduler = Scheduler(config)
results = await scheduler.run(target=args.target)
# Persist up_date + self-healed patterns
save_config(config)
# Exit 1 only when ALL sites failed (some errors like CDN 403 are expected)
all_failed = all(r.errors and r.articles_processed == 0 for r in results)
sys.exit(1 if all_failed else 0)
if __name__ == "__main__":
asyncio.run(main())