|
|
@@ -39,6 +39,12 @@ def get_user_input():
|
|
|
root.configure(bg='#f0f0f0')
|
|
|
root.option_add('*Font', '微软雅黑 10')
|
|
|
|
|
|
+ # 设置窗口图标(如果有的话)
|
|
|
+ try:
|
|
|
+ root.iconbitmap('icon.ico') # 如果有图标文件的话
|
|
|
+ except:
|
|
|
+ pass
|
|
|
+
|
|
|
# 创建主框架
|
|
|
main_frame = tk.Frame(root, bg='#f0f0f0', padx=20, pady=20)
|
|
|
main_frame.pack(fill=tk.BOTH, expand=True)
|
|
|
@@ -69,6 +75,14 @@ def get_user_input():
|
|
|
pady=10)
|
|
|
summary_text.pack(fill=tk.BOTH, expand=True)
|
|
|
|
|
|
+ # 添加字数统计
|
|
|
+ summary_count = tk.Label(summary_frame,
|
|
|
+ text="字数:0",
|
|
|
+ font=("微软雅黑", 10),
|
|
|
+ bg='#f0f0f0',
|
|
|
+ anchor='e')
|
|
|
+ summary_count.pack(fill=tk.X, padx=10)
|
|
|
+
|
|
|
# 创建明日工作计划输入区域
|
|
|
plan_frame = tk.LabelFrame(main_frame,
|
|
|
text="明日工作计划",
|
|
|
@@ -87,6 +101,14 @@ def get_user_input():
|
|
|
pady=10)
|
|
|
plan_text.pack(fill=tk.BOTH, expand=True)
|
|
|
|
|
|
+ # 添加字数统计
|
|
|
+ plan_count = tk.Label(plan_frame,
|
|
|
+ text="字数:0",
|
|
|
+ font=("微软雅黑", 10),
|
|
|
+ bg='#f0f0f0',
|
|
|
+ anchor='e')
|
|
|
+ plan_count.pack(fill=tk.X, padx=10)
|
|
|
+
|
|
|
# 创建底部控制区域
|
|
|
bottom_frame = tk.Frame(main_frame, bg='#f0f0f0', pady=10)
|
|
|
bottom_frame.pack(fill=tk.X)
|
|
|
@@ -120,6 +142,18 @@ def get_user_input():
|
|
|
height=2,
|
|
|
relief=tk.FLAT)
|
|
|
submit_button.pack(side=tk.RIGHT, padx=10)
|
|
|
+
|
|
|
+ # 添加字数统计更新函数
|
|
|
+ def update_counts(event=None):
|
|
|
+ summary_count.config(text=f"字数:{len(summary_text.get('1.0', tk.END).strip())}")
|
|
|
+ plan_count.config(text=f"字数:{len(plan_text.get('1.0', tk.END).strip())}")
|
|
|
+
|
|
|
+ # 绑定字数统计更新
|
|
|
+ summary_text.bind('<KeyRelease>', update_counts)
|
|
|
+ plan_text.bind('<KeyRelease>', update_counts)
|
|
|
+
|
|
|
+ # 初始更新字数统计
|
|
|
+ update_counts()
|
|
|
|
|
|
# 设置窗口居中
|
|
|
root.update_idletasks()
|
|
|
@@ -129,12 +163,6 @@ def get_user_input():
|
|
|
y = (root.winfo_screenheight() // 2) - (height // 2)
|
|
|
root.geometry(f'{width}x{height}+{x}+{y}')
|
|
|
|
|
|
- # 设置窗口图标(如果有的话)
|
|
|
- try:
|
|
|
- root.iconbitmap('icon.ico') # 如果有图标文件的话
|
|
|
- except:
|
|
|
- pass
|
|
|
-
|
|
|
root.mainloop()
|
|
|
return result["summary"], result["plan"], result["is_submitted"], result["keep_original"]
|
|
|
|
|
|
@@ -152,29 +180,29 @@ def close_chrome():
|
|
|
time.sleep(2)
|
|
|
|
|
|
async def run(playwright):
|
|
|
- # 确保Chrome已关闭
|
|
|
- close_chrome()
|
|
|
-
|
|
|
- # 使用用户实际的Chrome配置,配置查询chrome://version
|
|
|
- user_data_dir = r'C:/Users/zhens/AppData/Local/Google/Chrome/User Data'
|
|
|
-
|
|
|
- def text_to_div_html(text):
|
|
|
- """将多行文本转换为<div>...</div>格式的HTML"""
|
|
|
- lines = [line.strip() for line in text.strip().splitlines() if line.strip()]
|
|
|
- return ''.join(f'<div>{line}</div>' for line in lines)
|
|
|
+ try:
|
|
|
+ # 确保Chrome已关闭
|
|
|
+ close_chrome()
|
|
|
+
|
|
|
+ # 使用用户实际的Chrome配置,配置查询chrome://version
|
|
|
+ user_data_dir = r'C:/Users/zhens/AppData/Local/Google/Chrome/User Data'
|
|
|
+
|
|
|
+ def text_to_div_html(text):
|
|
|
+ """将多行文本转换为<div>...</div>格式的HTML"""
|
|
|
+ lines = [line.strip() for line in text.strip().splitlines() if line.strip()]
|
|
|
+ return ''.join(f'<div>{line}</div>' for line in lines)
|
|
|
|
|
|
- # 获取用户输入的日报内容
|
|
|
- summary_text, plan_text, is_submitted, keep_original = get_user_input()
|
|
|
-
|
|
|
- # 如果用户取消输入,直接退出程序
|
|
|
- if not is_submitted:
|
|
|
- print("用户取消了日报填写,程序退出")
|
|
|
- return
|
|
|
+ # 获取用户输入的日报内容
|
|
|
+ summary_text, plan_text, is_submitted, keep_original = get_user_input()
|
|
|
|
|
|
- summary_html = text_to_div_html(summary_text)
|
|
|
- plan_html = text_to_div_html(plan_text)
|
|
|
+ # 如果用户取消输入,直接退出程序
|
|
|
+ if not is_submitted:
|
|
|
+ print("用户取消了日报填写,程序退出")
|
|
|
+ return
|
|
|
+
|
|
|
+ summary_html = text_to_div_html(summary_text)
|
|
|
+ plan_html = text_to_div_html(plan_text)
|
|
|
|
|
|
- try:
|
|
|
# 使用已有的Chrome配置文件启动浏览器
|
|
|
context = await playwright.chromium.launch_persistent_context(
|
|
|
user_data_dir,
|
|
|
@@ -214,16 +242,6 @@ async def run(playwright):
|
|
|
editors = await page.query_selector_all('.maileditor-editorview[contenteditable="true"]')
|
|
|
print("找到输入框数量:", len(editors))
|
|
|
|
|
|
- # 打印每个输入框的父级HTML,帮助确认 data-qid,每次打开data-qid都会不同所以不准确
|
|
|
- # for i, editor in enumerate(editors):
|
|
|
- # parent = await editor.evaluate_handle('el => el.closest("div.question")')
|
|
|
- # parent_html = await parent.evaluate('el => el.outerHTML')
|
|
|
- # print(f"输入框{i+1}父级HTML:\n{parent_html}\n")
|
|
|
-
|
|
|
- # if len(editors) >= 2:
|
|
|
- # await editors[0].evaluate(f'el => el.innerHTML = `{summary_html}`')
|
|
|
- # await editors[1].evaluate(f'el => el.innerHTML = `{plan_html}`')
|
|
|
-
|
|
|
# 今日工作总结输入
|
|
|
# 1. 先点击输入框,确保获得焦点
|
|
|
await page.locator('div.question:has-text("今日工作总结") .maileditor-editorview[contenteditable="true"]').click()
|
|
|
@@ -255,18 +273,24 @@ async def run(playwright):
|
|
|
# 点击提交按钮
|
|
|
# 1. 等待提交按钮出现
|
|
|
await page.wait_for_selector('button.FillFooter_confirm__0ClPl', timeout=60000)
|
|
|
- # # 2. 点击提交按钮,添加延迟模拟真实点击
|
|
|
+ # 2. 点击提交按钮,添加延迟模拟真实点击
|
|
|
await page.click('button.FillFooter_confirm__0ClPl', delay=100)
|
|
|
|
|
|
# 等待提交完成
|
|
|
# 给系统足够的时间来处理提交操作
|
|
|
await asyncio.sleep(5)
|
|
|
+
|
|
|
+ # 显示提交成功提示
|
|
|
+ print("日报提交成功!")
|
|
|
|
|
|
+ except Exception as e:
|
|
|
+ print(f"提交过程中发生错误: {str(e)}")
|
|
|
+ raise
|
|
|
finally:
|
|
|
# 确保浏览器正常关闭
|
|
|
await context.close()
|
|
|
except Exception as e:
|
|
|
- print(f"发生错误: {str(e)}")
|
|
|
+ print(f"程序运行过程中发生错误: {str(e)}")
|
|
|
raise
|
|
|
|
|
|
# 主函数,用于启动 playwright 并调用 run 函数
|