diff --git a/main.py b/main.py index 3df3842..77b8260 100644 --- a/main.py +++ b/main.py @@ -187,6 +187,7 @@ def save_image(url,file_name): if response.status_code == 200: with open(f'{save_path}/{valid_file_name}.jpg', 'wb') as f: f.write(response.content) + log(f"图片保存成功:{save_path}/{valid_file_name}.jpg") except Exception as e: log(e,"error") @@ -219,12 +220,16 @@ class PaginatedContainer(ft.Column): items=[ ft.PopupMenuItem(text="导出为JSON", on_click=self.export_json), ft.PopupMenuItem(text="导出为Excel", on_click=self.export_excel), - # ft.PopupMenuItem(text="导出为HTML", on_click=self.export_html), ft.PopupMenuItem(text="导出为Markdown", on_click=self.export_markdown), ], tooltip="导出为", ) + if isinstance(self.data[0], Message): + export_control.items.append( + ft.PopupMenuItem(text="导出为HTML", on_click=self.export_html) + ) + return ft.Column( [ ft.Row( @@ -328,9 +333,141 @@ class PaginatedContainer(ft.Column): log(f"导出成功 请查看 {now_login_user.uin}_{self.title}_data.xlsx","success") - def export_html(self,e): - print("Exporting HTML...") + def export_html(self, e): + # HTML 头部和样式 + html_start = ''' + + + + + + Exported Data + + + +
+ ''' + + # HTML 中间部分,动态生成每个数据项的卡片 + html_middle = '' + for item in self.data: + # 处理每个数据项的内容,包括用户头像、用户名、发布时间、内容等 + html_middle += f''' +
+
+ avatar + +
+
+

{item.content}

+ {f'post-image' if item.images and 'http' in item.images else ''} +
+ +
+ ''' + # HTML 尾部 + html_end = ''' +
+ + + ''' + + # 生成最终的 HTML 文件 + html_content = html_start + html_middle + html_end + + # 保存 HTML 文件 + file_name = f"{now_login_user.uin}_{self.title}_data.html" + file_path = f"{save_path}/{file_name}" + with open(file_path, 'w', encoding='utf-8') as f: + f.write(html_content) + + # 日志记录 + log(f"导出成功 请查看 {file_name}", "success") + + + def export_markdown(self,e): # 创建 Markdown 内容的列表 markdown_lines = []