Update 网络收集.py
This commit is contained in:
+7
-16
@@ -379,6 +379,7 @@ with open('2.txt', 'r', encoding='utf-8') as file, open('2.txt', 'w', encoding='
|
|||||||
|
|
||||||
###############################################################
|
###############################################################
|
||||||
import re
|
import re
|
||||||
|
|
||||||
def parse_file(input_file_path, output_file_name):
|
def parse_file(input_file_path, output_file_name):
|
||||||
# 正则表达式匹配从'//'开始到第一个'/'或第一个'::'结束的部分
|
# 正则表达式匹配从'//'开始到第一个'/'或第一个'::'结束的部分
|
||||||
ip_or_domain_pattern = re.compile(r'//([^/:]*:[^/:]*::[^/:]*|[^/]*)')
|
ip_or_domain_pattern = re.compile(r'//([^/:]*:[^/:]*::[^/:]*|[^/]*)')
|
||||||
@@ -425,6 +426,7 @@ parse_file('2.txt', '2.txt')
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import time
|
import time
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
@@ -446,13 +448,8 @@ def merge_and_filter():
|
|||||||
|
|
||||||
total_lines = len(lines)
|
total_lines = len(lines)
|
||||||
|
|
||||||
import time
|
# 处理输入文件中的数据并进行检测
|
||||||
import cv2
|
with open(output_file_path, 'a', encoding='utf-8') as output_file:
|
||||||
from tqdm import tqdm
|
|
||||||
|
|
||||||
# 处理输入文件中的数据并进行检测
|
|
||||||
with open(output_file_path, 'a', encoding='utf-8') as output_file:
|
|
||||||
valid_line_count = 0
|
|
||||||
for i, line in tqdm(enumerate(lines), total=total_lines, desc="Processing", unit='line'):
|
for i, line in tqdm(enumerate(lines), total=total_lines, desc="Processing", unit='line'):
|
||||||
if 'genre' in line:
|
if 'genre' in line:
|
||||||
output_file.write(line)
|
output_file.write(line)
|
||||||
@@ -466,7 +463,6 @@ with open(output_file_path, 'a', encoding='utf-8') as output_file:
|
|||||||
if ip_key and ip_key in detected_ips:
|
if ip_key and ip_key in detected_ips:
|
||||||
if detected_ips[ip_key]['status'] == 'ok':
|
if detected_ips[ip_key]['status'] == 'ok':
|
||||||
output_file.write(line)
|
output_file.write(line)
|
||||||
valid_line_count += 1
|
|
||||||
elif ip_key:
|
elif ip_key:
|
||||||
cap = cv2.VideoCapture(url)
|
cap = cv2.VideoCapture(url)
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
@@ -480,15 +476,12 @@ with open(output_file_path, 'a', encoding='utf-8') as output_file:
|
|||||||
if frame_count >= 50:
|
if frame_count >= 50:
|
||||||
detected_ips[ip_key] = {'status': 'ok'}
|
detected_ips[ip_key] = {'status': 'ok'}
|
||||||
output_file.write(line)
|
output_file.write(line)
|
||||||
valid_line_count += 1
|
|
||||||
else:
|
else:
|
||||||
detected_ips[ip_key] = {'status': 'fail'}
|
detected_ips[ip_key] = {'status': 'fail'}
|
||||||
print(f"有效的总行数为:{valid_line_count}")
|
print(f"有效的总行数为:{valid_line_count}")
|
||||||
|
|
||||||
|
|
||||||
# 合并任意字符加上网络收集.txt 的文件
|
# 合并任意字符加上网络收集.txt 的文件
|
||||||
all_files = [f for f in os.listdir(os.getcwd()) if f.endswith('网络收集.txt')]
|
all_files = [f for f in os.listdir(os.getcwd()) if f.endswith('网络收集.txt')]
|
||||||
with open(output_file_path, 'a', encoding='utf-8') as main_output:
|
with open(output_file_path, 'a', encoding='utf-8') as main_output:
|
||||||
for file_name in all_files:
|
for file_name in all_files:
|
||||||
if file_name!= output_file_path:
|
if file_name!= output_file_path:
|
||||||
with open(file_name, 'r', encoding='utf-8') as other_file:
|
with open(file_name, 'r', encoding='utf-8') as other_file:
|
||||||
@@ -700,5 +693,3 @@ for file in files_to_remove:
|
|||||||
else: # 如果文件不存在,则提示异常并打印提示信息
|
else: # 如果文件不存在,则提示异常并打印提示信息
|
||||||
print(f"文件 {file} 不存在,跳过删除。")
|
print(f"文件 {file} 不存在,跳过删除。")
|
||||||
print("任务运行完毕,频道列表可查看文件夹内源.txt文件!")
|
print("任务运行完毕,频道列表可查看文件夹内源.txt文件!")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user