From 97be17303f8a4de91c7751e3bc97f6d901b5817a Mon Sep 17 00:00:00 2001 From: jinye_huang Date: Thu, 8 May 2025 22:39:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E4=B8=ADtag=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/tweet_generator.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/utils/tweet_generator.py b/utils/tweet_generator.py index fb72495..d4befeb 100644 --- a/utils/tweet_generator.py +++ b/utils/tweet_generator.py @@ -58,7 +58,7 @@ class tweetContent: self.variant_index = variant_index try: - self.title, self.content = self.split_content(result) + self.title, self.content, self.tag = self.split_content(result) self.json_data = self.gen_result_json() except Exception as e: logging.error(f"Failed to parse AI result for {article_index}_{variant_index}: {e}") @@ -84,11 +84,14 @@ class tweetContent: processed_result = result if "" in result: processed_result = result.split("", 1)[1] # Take part after - - title = processed_result.split("title>", 1)[1].split("", 1)[0] - content = processed_result.split("content>", 1)[1].split("", 1)[0] + + # 以json 格式输出 + json_data = json.loads(processed_result) + title = json_data.get("title") + content = json_data.get("content") + tag = json_data.get("tag") # --- End Existing Logic --- - return title.strip(), content.strip() + return title.strip(), content.strip(), tag.strip() except Exception as e: logging.warning(f"解析内容时出错: {e}, 返回空字符串") return "", "" @@ -96,12 +99,14 @@ class tweetContent: def gen_result_json(self): json_file = { "title": self.title, - "content": self.content + "content": self.content, + "tag": self.tag } # Add error flag if it exists if hasattr(self, 'json_data') and self.json_data.get('error'): json_file['error'] = True json_file['raw_result'] = self.json_data.get('raw_result') + logging.info(f"Generated JSON: {json_file}") return json_file def get_json_data(self):