python图片查询去重,检测文件是否存在

自用脚本,留着备份

import os
import re

# ---------- 配置 ----------
ok_dir = r"C:\Users\18102\Downloads\ok"
output_missing = "missing.txt"  # 输出到当前脚本所在目录

# ---------- 生成所有目标域名 (aaa0001.com ~ aaa1167.com) ----------
expected_domains = set()
for i in range(1, 1168):  # 0001 到 1167
    domain = f"aaa{i:04d}.com"
    expected_domains.add(domain)

# ---------- 获取 ok 文件夹中已存在的截图域名 ----------
existing_domains = set()
if os.path.exists(ok_dir):
    for filename in os.listdir(ok_dir):
        if filename.lower().endswith('.png'):
            base = os.path.splitext(filename)[0]
            # 去除可能存在的 "(序号)" 后缀(如 "aaa0001 (1)")
            match = re.match(r'^(.*?)(?:\s*\(\d+\))?$', base)
            if match:
                domain = match.group(1)
                existing_domains.add(domain)
else:
    print(f"⚠️ 警告:{ok_dir} 目录不存在,请确认路径。")

# ---------- 计算缺失的域名 ----------
missing_domains = expected_domains - existing_domains

# ---------- 输出缺失的原始访问链接 ----------
with open(output_missing, 'w', encoding='utf-8') as f:
    for domain in sorted(missing_domains):
        url = f"http://aaa001.com/?url=http://{domain}"
        f.write(url + '\n')

print(f"✅ 缺失的网址已保存到 {output_missing}")
print(f"📌 共缺失 {len(missing_domains)} 个。")

 

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容