-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify_available.py
49 lines (43 loc) · 1.75 KB
/
verify_available.py
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
import json
import requests
from concurrent.futures import ThreadPoolExecutor, as_completed
def send_notification(message):
notify_url = "https://open.feishu.cn/open-apis/bot/v2/hook/007c39d4-a4be-431b-b5c4-6e37e04ee4c6" # 替换为实际的机器人URL
notify_headers = {'Content-Type': 'application/json'}
notify_data = {
"msg_type": "text",
"content": {
"text": message
}
}
requests.post(notify_url, headers=notify_headers, json=notify_data)
def check_url(image):
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
}
try:
response = requests.head(image['url'], headers=headers, timeout=10, allow_redirects=True)
if response.status_code != 200:
message = f"{image['id']} 不可用, http状态码: {response.status_code},请来一个同学修复一下"
send_notification(message)
return message
return None
except requests.RequestException as e:
# 如果429,不管
if response.status_code == 429:
return None
message = f"{image['id']} 不可用, error: {str(e)},请来一个同学修复一下"
send_notification(message)
return message
# 从vm-iso.json中读取镜像列表
with open('vm-iso.json', 'r') as f:
imageList = json.load(f)
# 使用线程池并行检查URL
with ThreadPoolExecutor(max_workers=10) as executor:
# 提交所有任务
future_to_url = {executor.submit(check_url, image): image for image in imageList}
# 获取结果
for future in as_completed(future_to_url):
result = future.result()
if result:
print(result)