def scan_thread(keyword, catalog_json):
# Check each thread, threads who contains the keyword are returned
matched_threads = []
for i in range(len(catalog_json)):
for thread in catalog_json[i]["threads"]:
regex = r'\b{0}\b'.format(keyword)
# Search thread title
if 'sub' in thread:
if re.search(regex, str(thread["sub"]), re.IGNORECASE):
matched_threads.append(thread["no"])
# Search OPs post body
if 'com' in thread:
if re.search(regex, str(thread["com"]), re.IGNORECASE):
matched_threads.append(thread["no"])
return matched_threads
评论列表
文章目录