Spaces:
Runtime error
Runtime error
Create deduper_e.py
Browse files- agent/deduper_e.py +50 -0
agent/deduper_e.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
去重 + 纯邮箱输出
|
| 3 |
+
读 verified.json,跨批次去重,输出纯文本 emails.txt
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import json
|
| 7 |
+
import sys
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
| 10 |
+
|
| 11 |
+
from agent.config_e import DATA_DIR, BATCHES_DIR
|
| 12 |
+
|
| 13 |
+
VERIFIED_FILE = DATA_DIR / "verified.json"
|
| 14 |
+
FINAL_OUTPUT_FILE = DATA_DIR / "emails.txt"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def dedupe_all():
|
| 18 |
+
all_emails = set()
|
| 19 |
+
|
| 20 |
+
# 合并所有批次的验证结果
|
| 21 |
+
if VERIFIED_FILE.exists():
|
| 22 |
+
with open(VERIFIED_FILE, "r", encoding="utf-8") as f:
|
| 23 |
+
data = json.load(f)
|
| 24 |
+
for item in data:
|
| 25 |
+
email = item.get("email", "").strip().lower()
|
| 26 |
+
if email and "@" in email:
|
| 27 |
+
all_emails.add(email)
|
| 28 |
+
|
| 29 |
+
# 也合并之前批次输出的纯文本
|
| 30 |
+
if BATCHES_DIR.exists():
|
| 31 |
+
for f in sorted(BATCHES_DIR.glob("emails_*.txt")):
|
| 32 |
+
with open(f, "r", encoding="utf-8") as fh:
|
| 33 |
+
for line in fh:
|
| 34 |
+
email = line.strip().lower()
|
| 35 |
+
if email and "@" in email:
|
| 36 |
+
all_emails.add(email)
|
| 37 |
+
|
| 38 |
+
# 排序输出
|
| 39 |
+
sorted_emails = sorted(all_emails)
|
| 40 |
+
|
| 41 |
+
with open(FINAL_OUTPUT_FILE, "w", encoding="utf-8") as f:
|
| 42 |
+
for em in sorted_emails:
|
| 43 |
+
f.write(em + "\n")
|
| 44 |
+
|
| 45 |
+
print(f"[deduper] 去重后总数: {len(sorted_emails)}")
|
| 46 |
+
print(f"[deduper] 输出: {FINAL_OUTPUT_FILE}")
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
if __name__ == "__main__":
|
| 50 |
+
dedupe_all()
|