From d0a4583cb15d55a98e3c35e78417c6a03bd36c1b Mon Sep 17 00:00:00 2001 From: shengyudong Date: Thu, 5 Feb 2026 11:47:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9F=A5=E8=AF=A2=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=9A=E5=8E=BB=E9=99=A4=E8=B7=A8=E8=A1=A8=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=EF=BC=8C=E5=8D=95=E7=8B=AC=E8=8E=B7=E5=8F=96=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E6=A0=87=E9=A2=98=E5=92=8C=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- article_auto_image_matching.py | 40 ++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/article_auto_image_matching.py b/article_auto_image_matching.py index 3af036c..4c0b806 100644 --- a/article_auto_image_matching.py +++ b/article_auto_image_matching.py @@ -93,31 +93,53 @@ class ArticleImageMatcher: SELECT at.id, at.article_id, - at.coze_tag, - a.title, - a.content + at.coze_tag FROM ai_article_tags at - INNER JOIN ai_articles a ON at.article_id = a.id WHERE at.coze_tag IS NOT NULL AND at.coze_tag != '' AND NOT EXISTS ( SELECT 1 FROM ai_article_images ai WHERE ai.article_id = at.article_id ) - AND a.status = 'pending_review' + AND at.article_id IN ( + SELECT id FROM ai_articles + WHERE status = 'pending_review' + ) ORDER BY at.id DESC LIMIT %s """ cursor.execute(sql, (limit,)) results = cursor.fetchall() - if results: - logger.info(f"查询到 {len(results)} 篇需要匹配图片的文章") - self.log_to_database('INFO', f"查询到需要匹配图片的文章", f"数量: {len(results)}") + # 为每个结果添加文章标题和内容 + processed_results = [] + for row in results: + # 查询文章标题和内容 + article_sql = """ + SELECT title, content + FROM ai_articles + WHERE id = %s + """ + cursor.execute(article_sql, (row['article_id'],)) + article_data = cursor.fetchone() + + if article_data: + processed_row = { + 'id': row['id'], + 'article_id': row['article_id'], + 'coze_tag': row['coze_tag'], + 'title': article_data['title'], + 'content': article_data['content'] + } + processed_results.append(processed_row) + + if processed_results: + logger.info(f"查询到 {len(processed_results)} 篇需要匹配图片的文章") + self.log_to_database('INFO', f"查询到需要匹配图片的文章", f"数量: {len(processed_results)}") else: logger.info("未查询到需要匹配图片的文章") - return results + return processed_results finally: connection.close() except Exception as e: