Update 组播定期检测.py

This commit is contained in:
frxz751113
2024-08-20 22:58:49 +08:00
committed by GitHub
parent 052cd24fb3
commit 7b31cda66b
+1 -12
View File
@@ -2,10 +2,8 @@
import cv2 import cv2
import time import time
from tqdm import tqdm from tqdm import tqdm
# 初始化字典
# 初始化酒店源字典
detected_ips = {} detected_ips = {}
def get_ip_key(url): def get_ip_key(url):
"""从URL中提取IP地址,并构造一个唯一的键""" """从URL中提取IP地址,并构造一个唯一的键"""
start = url.find('://') + 3 start = url.find('://') + 3
@@ -17,24 +15,19 @@ def get_ip_key(url):
break break
dot_count += 1 dot_count += 1
return url[start:end] if dot_count == 3 else None return url[start:end] if dot_count == 3 else None
# 设置固定的文件夹路径 # 设置固定的文件夹路径
folder_path = 'playlist' folder_path = 'playlist'
# 确保文件夹路径存在 # 确保文件夹路径存在
if not os.path.isdir(folder_path): if not os.path.isdir(folder_path):
print("指定的文件夹不存在。") print("指定的文件夹不存在。")
sys.exit() sys.exit()
# 遍历文件夹中的所有.txt文件 # 遍历文件夹中的所有.txt文件
for filename in os.listdir(folder_path): for filename in os.listdir(folder_path):
if filename.endswith('.txt'): if filename.endswith('.txt'):
file_path = os.path.join(folder_path, filename) file_path = os.path.join(folder_path, filename)
# 读取文件内容 # 读取文件内容
with open(file_path, 'r', encoding='utf-8') as file: with open(file_path, 'r', encoding='utf-8') as file:
lines = file.readlines() lines = file.readlines()
# 准备写回文件 # 准备写回文件
with open(file_path, 'w', encoding='utf-8') as output_file: with open(file_path, 'w', encoding='utf-8') as output_file:
# 使用tqdm显示进度条 # 使用tqdm显示进度条
@@ -42,13 +35,11 @@ for filename in os.listdir(folder_path):
if 'genre' in line: if 'genre' in line:
output_file.write(line) output_file.write(line)
continue continue
parts = line.split(',', 1) parts = line.split(',', 1)
if len(parts) == 2: if len(parts) == 2:
channel_name, url = parts channel_name, url = parts
channel_name = channel_name.strip() channel_name = channel_name.strip()
url = url.strip() url = url.strip()
ip_key = get_ip_key(url) ip_key = get_ip_key(url)
if ip_key in detected_ips and detected_ips[ip_key]['status'] == 'ok': if ip_key in detected_ips and detected_ips[ip_key]['status'] == 'ok':
output_file.write(line) output_file.write(line)
@@ -63,13 +54,11 @@ for filename in os.listdir(folder_path):
break break
frame_count += 1 frame_count += 1
cap.release() cap.release()
if frame_count >= 200: if frame_count >= 200:
detected_ips[ip_key] = {'status': 'ok'} detected_ips[ip_key] = {'status': 'ok'}
output_file.write(line) output_file.write(line)
else: else:
detected_ips[ip_key] = {'status': 'fail'} detected_ips[ip_key] = {'status': 'fail'}
# 打印检测结果 # 打印检测结果
for ip_key, result in detected_ips.items(): for ip_key, result in detected_ips.items():
print(f"IP Key: {ip_key}, Status: {result['status']}") print(f"IP Key: {ip_key}, Status: {result['status']}")