63 lines
2.3 KiB
Python
63 lines
2.3 KiB
Python
import os
|
|
import re
|
|
|
|
PODCAST_DIR = "content/podcast"
|
|
POSTS_DIR = "content/posts"
|
|
|
|
pod_files = sorted([f for f in os.listdir(PODCAST_DIR) if f.startswith("ep-") and f.endswith(".yaml")])
|
|
post_files = sorted([f for f in os.listdir(POSTS_DIR) if f.endswith(".md")])
|
|
|
|
podcasts = []
|
|
for pf in pod_files:
|
|
with open(os.path.join(PODCAST_DIR, pf), 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
title_m = re.search(r'^title:\s*"?(.+?)"?$', content, re.M)
|
|
date_m = re.search(r'^date:\s*(.+)$', content, re.M)
|
|
summary_m = re.search(r'^summary:\s*"?(.+?)"?$', content, re.M)
|
|
|
|
title = title_m.group(1) if title_m else ""
|
|
date = date_m.group(1) if date_m else ""
|
|
summary = summary_m.group(1) if summary_m else ""
|
|
podcasts.append({"file": pf, "title": title, "date": date, "summary": summary})
|
|
|
|
posts = []
|
|
for pf in post_files:
|
|
with open(os.path.join(POSTS_DIR, pf), 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
title_m = re.search(r'^title:\s*"?(.+?)"?$', content, re.M)
|
|
date_m = re.search(r'^date:\s*(.+)$', content, re.M)
|
|
|
|
title = title_m.group(1) if title_m else ""
|
|
date = date_m.group(1) if date_m else ""
|
|
posts.append({"file": pf, "title": title, "date": date, "body": content})
|
|
|
|
print(f"Total podcasts: {len(podcasts)}")
|
|
print(f"Total posts: {len(posts)}")
|
|
|
|
for p in podcasts:
|
|
print(f"\n==========================================")
|
|
print(f"PODCAST: {p['file']} | Date: {p['date']} | Title: {p['title']}")
|
|
|
|
clean_title = re.sub(r'^\d{3}:\s*', '', p['title']).lower().strip()
|
|
keywords = [w for w in clean_title.split() if len(w) > 3]
|
|
|
|
matches = []
|
|
for post in posts:
|
|
post_title = post['title'].lower()
|
|
post_body = post['body'].lower()
|
|
|
|
# Check title similarity or date proximity or keywords
|
|
if clean_title in post_title or clean_title in post_body:
|
|
matches.append((post, "direct_text_match"))
|
|
elif any(kw in post_title for kw in keywords if len(kw) > 4):
|
|
matches.append((post, "title_keyword_match"))
|
|
|
|
if matches:
|
|
for m, reason in matches:
|
|
print(f" [MATCH ({reason})] Post: {m['file']} | Date: {m['date']} | Title: {m['title']}")
|
|
else:
|
|
print(" ❌ NO MATCH FOUND IN POSTS")
|
|
|