Spaces:
Running
Running
Upload 3 files
Browse files- getNode.py +15 -6
- getServerList.py +5 -0
- requirements.txt +1 -0
getNode.py
CHANGED
@@ -5,7 +5,7 @@ from server.decoder import decode_url_to_configs
|
|
5 |
import random
|
6 |
from fastapi import APIRouter,BackgroundTasks
|
7 |
from server.utils import subscription_link_list,getRandomSubscribeUrl,delete_invalid_url_in_txt
|
8 |
-
|
9 |
|
10 |
router = APIRouter()
|
11 |
@router.get('/')
|
@@ -14,17 +14,26 @@ def getNode(background_tasks: BackgroundTasks)->str:
|
|
14 |
SubscribeUrlList = subscription_link_list(router.fileName)
|
15 |
# 直接用现成的认为可用然后直接返回,之后再删不可用的
|
16 |
randomSubscribeUrl= getRandomSubscribeUrl(SubscribeUrlList)
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
#background_tasks.add_task(delete_invalid_url_in_txt, router.fileName)
|
21 |
-
return NodeStr
|
22 |
|
23 |
def RandomNode(NodeList:list)->str:
|
24 |
#返回一个节点信息
|
25 |
return random.choice(NodeList)
|
26 |
|
27 |
-
|
28 |
def dump_configs(url:str)->list:
|
29 |
#返回全部节点信息的列表
|
30 |
configs = decode_url_to_configs(url)
|
|
|
5 |
import random
|
6 |
from fastapi import APIRouter,BackgroundTasks
|
7 |
from server.utils import subscription_link_list,getRandomSubscribeUrl,delete_invalid_url_in_txt
|
8 |
+
from func_timeout import func_set_timeout, FunctionTimedOut
|
9 |
|
10 |
router = APIRouter()
|
11 |
@router.get('/')
|
|
|
14 |
SubscribeUrlList = subscription_link_list(router.fileName)
|
15 |
# 直接用现成的认为可用然后直接返回,之后再删不可用的
|
16 |
randomSubscribeUrl= getRandomSubscribeUrl(SubscribeUrlList)
|
17 |
+
try:
|
18 |
+
NodeList = dump_configs(randomSubscribeUrl)
|
19 |
+
NodeStr = RandomNode(NodeList)
|
20 |
+
# background_tasks.add_task(delete_invalid_url_in_txt, router.fileName)
|
21 |
+
return NodeStr
|
22 |
+
except FunctionTimedOut:
|
23 |
+
print(f"解析订阅链接{randomSubscribeUrl} 时超时")
|
24 |
+
return ''
|
25 |
+
except Exception as e:
|
26 |
+
# 如果解析失败,打印错误信息并继续处理下一个订阅链接
|
27 |
+
print(f"解析订阅链接 {randomSubscribeUrl} 时发生错误: {e}")
|
28 |
+
return ''
|
29 |
+
|
30 |
|
|
|
|
|
31 |
|
32 |
def RandomNode(NodeList:list)->str:
|
33 |
#返回一个节点信息
|
34 |
return random.choice(NodeList)
|
35 |
|
36 |
+
@func_set_timeout(5) # 设置超时时间为5秒
|
37 |
def dump_configs(url:str)->list:
|
38 |
#返回全部节点信息的列表
|
39 |
configs = decode_url_to_configs(url)
|
getServerList.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
#!/usr/bin/env python
|
2 |
# -*- coding: utf-8 -*-
|
|
|
|
|
3 |
from server.decoder import decode_url_to_configs
|
4 |
import base64
|
5 |
from fastapi import APIRouter,BackgroundTasks
|
@@ -20,6 +22,8 @@ def getServerList(background_tasks: BackgroundTasks)->str:
|
|
20 |
NodeList = dump_configs(subscribe_url)
|
21 |
# 如果解析成功,将解析出的节点列表添加到总列表中
|
22 |
all_node_lists.extend(NodeList)
|
|
|
|
|
23 |
except Exception as e:
|
24 |
# 如果解析失败,打印错误信息并继续处理下一个订阅链接
|
25 |
print(f"解析订阅链接 {subscribe_url} 时发生错误: {e}")
|
@@ -38,6 +42,7 @@ def getServerList(background_tasks: BackgroundTasks)->str:
|
|
38 |
|
39 |
|
40 |
|
|
|
41 |
def dump_configs(url:str)->list:
|
42 |
#返回全部节点信息的列表
|
43 |
configs = decode_url_to_configs(url)
|
|
|
1 |
#!/usr/bin/env python
|
2 |
# -*- coding: utf-8 -*-
|
3 |
+
from func_timeout import func_set_timeout, FunctionTimedOut
|
4 |
+
|
5 |
from server.decoder import decode_url_to_configs
|
6 |
import base64
|
7 |
from fastapi import APIRouter,BackgroundTasks
|
|
|
22 |
NodeList = dump_configs(subscribe_url)
|
23 |
# 如果解析成功,将解析出的节点列表添加到总列表中
|
24 |
all_node_lists.extend(NodeList)
|
25 |
+
except FunctionTimedOut:
|
26 |
+
print(f"解析订阅链接{subscribe_url} 时超时")
|
27 |
except Exception as e:
|
28 |
# 如果解析失败,打印错误信息并继续处理下一个订阅链接
|
29 |
print(f"解析订阅链接 {subscribe_url} 时发生错误: {e}")
|
|
|
42 |
|
43 |
|
44 |
|
45 |
+
@func_set_timeout(5) # 设置超时时间为5秒
|
46 |
def dump_configs(url:str)->list:
|
47 |
#返回全部节点信息的列表
|
48 |
configs = decode_url_to_configs(url)
|
requirements.txt
CHANGED
@@ -5,4 +5,5 @@ aiohttp==3.7.3
|
|
5 |
fastapi==0.95.0
|
6 |
urllib3==2.0.7
|
7 |
uvicorn
|
|
|
8 |
#这个适用hf和windows
|
|
|
5 |
fastapi==0.95.0
|
6 |
urllib3==2.0.7
|
7 |
uvicorn
|
8 |
+
func_timeout
|
9 |
#这个适用hf和windows
|