This repository was archived by the owner on Feb 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathfunction.py
More file actions
55 lines (48 loc) · 1.54 KB
/
function.py
File metadata and controls
55 lines (48 loc) · 1.54 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
import requests
from loguru import logger
from time import sleep
import json
conf = open('configs.json', 'r', encoding='utf-8').read()
confs = json.loads(conf)
bot_token = confs['bot_token']
chat_id = confs['chat_id']
clash_api = confs['clash_api']
sub_url = confs['sub_url']
airport_name = confs['airport_name'].replace('-', '\\')
hosting = confs['hosting']
fail_node = []
proxies = {
'http': 'http://127.0.0.1:7890',
'https': 'http://127.0.0.1:7890',
}
def send_message(text):
message_data = {
'chat_id': chat_id,
'text': text,
'parse_mode': 'MarkdownV2'
}
try:
res = requests.post(f'https://api.telegram.org/bot{bot_token}/sendMessage', json=message_data, proxies=proxies)
if res.status_code == 200:
logger.info(res.json())
else:
logger.warning('发送通知信息失败:')
logger.warning(res.json())
except Exception as e:
logger.error(e)
def test_proxies():
try:
fail_node.clear()
resp = requests.get(f"{clash_api}/providers/proxies")
data = resp.json()['providers']['自动选择']['proxies']
resp.close()
for i in range(len(data)):
node_name = data[i]['name']
delay1 = data[i]['history'][0]['delay']
delay2 = data[i]['history'][1]['delay']
if delay1 == 0 and delay2 == 0:
fail_node.append(''.join(node_name))
return len(data)
except Exception as e:
logger.warning(f"数据获取发生错误:{e}")
sleep(3)