Skip to content

Commit

Permalink
若干更新
Browse files Browse the repository at this point in the history
1.从上游仓库同步更新,Commit:“更新版本号”
2.修复在获取已回复帖子列表时无法识别置顶帖(绿色链接)的问题
3.新增“执行超时时间计算器”(ExecutionTimeoutCalculator.py)
  • Loading branch information
pooneyy committed Jul 20, 2023
1 parent f659f38 commit e94987f
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 8 deletions.
92 changes: 92 additions & 0 deletions ExecutionTimeoutCalculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import tkinter as tk
from tkinter import messagebox, ttk
import tkinter.font as tkFont
from datetime import datetime, timedelta

FONT_SIZE = 12
SPINBOX_WIDTH = 4

def calculate_timeout(event=None):
try:
reply_limit = int(reply_limit_entry.get())
time_interval_end = float(time_interval_end_entry.get())
polling_time = float(polling_time_entry.get())
# 组合时间字符串
start_time_str = f"{start_time_hour.get()}:{start_time_minute.get()}:{start_time_second.get()}"
# 将时间字符串转换为 datetime 对象
start_time = datetime.strptime(start_time_str, "%H:%M:%S")
# start_time = datetime.strptime(start_time_entry.get() ,"%H:%M:%S")

now = datetime.now()
if now > start_time:
start_time = start_time + timedelta(days=1)

timeout = (time_interval_end + polling_time) * (reply_limit + 1)

end_time = start_time + timedelta(seconds=timeout)

result_label.config(text=f"执行超时时间:{int(timeout)}\n计划启动时间:{start_time.time()}\n最迟结束时间:{end_time.time()}")

if timeout > 86400:
messagebox.showwarning("超时时间过长", "计算得到的超时时间已经超过了云函数可允许的最大超时时间(86400秒)。请重新调整输入参数。")
except ValueError:
messagebox.showerror("错误", "请输入有效的数字参数。")

# 创建主窗口
root = tk.Tk()
root.title("云函数执行超时时间计算器")

# 创建自定义字体
font = tkFont.Font(family="SimSun", size=FONT_SIZE)

# 创建输入参数的标签和文本框
reply_limit_label = tk.Label(root, text="回复次数限制:", font=font)
reply_limit_label.grid(row=0, column=0, padx=5, pady=5)
reply_limit_entry = tk.Entry(root, font=font)
reply_limit_entry.grid(row=0, column=1, padx=5, pady=5)
reply_limit_entry.insert(0, "10")

time_interval_end_label = tk.Label(root, text="两次回复的时间间隔最大值(秒):", font=font)
time_interval_end_label.grid(row=1, column=0, padx=5, pady=5)
time_interval_end_entry = tk.Entry(root, font=font)
time_interval_end_entry.grid(row=1, column=1, padx=5, pady=5)
time_interval_end_entry.focus_set() # 焦点位于输入框

polling_time_label = tk.Label(root, text="循环间隔(秒):", font=font)
polling_time_label.grid(row=2, column=0, padx=5, pady=5)
polling_time_entry = tk.Entry(root, font=font)
polling_time_entry.grid(row=2, column=1, padx=5, pady=5)
polling_time_entry.insert(0, "5")

start_time_label = tk.Label(root, text="计划启动时间(时:分:秒):", font=font)
start_time_label.grid(row=3, column=0, padx=5, pady=5)

start_time_frame = ttk.Frame(root)
start_time_frame.grid(row=3, column=1, padx=5, pady=5)
start_time_hour = ttk.Spinbox(start_time_frame, from_=0, to=23, width=SPINBOX_WIDTH, font=font)
start_time_minute = ttk.Spinbox(start_time_frame, from_=0, to=59, width=SPINBOX_WIDTH, font=font)
start_time_second = ttk.Spinbox(start_time_frame, from_=0, to=59, width=SPINBOX_WIDTH, font=font)
start_time_hour.set('08')
start_time_minute.set('30')
start_time_second.set('00')
start_time_hour.grid(row=0, column=0, padx=5, pady=5)
start_time_minute.grid(row=0, column=1, padx=5, pady=5)
start_time_second.grid(row=0, column=2, padx=5, pady=5)

# start_time_entry = tk.Entry(root, font=font)
# start_time_entry.grid(row=3, column=1, padx=5, pady=5)
# start_time_entry.insert(0, "08:30:00")

# 创建计算按钮
calculate_button = tk.Button(root, text="计算超时时间", command=calculate_timeout, font=font)
calculate_button.grid(row=4, column=0, columnspan=2, padx=5, pady=5)

# 创建结果展示标签
result_label = tk.Label(root, heigh=3, text="", font=font)
result_label.grid(row=5, column=0, columnspan=2, padx=5, pady=5)

# 绑定回车键与计算事件
root.bind("<Return>", calculate_timeout)

# 启动主循环
root.mainloop()
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# CaoLiu_AutoReply(腾讯云函数)

注:此分支基于 [0honus0/CaoLiu_AutoReply at 7698edb87567d8a5b0e78a9dbd28df235442b38d](https://github.com/0honus0/CaoLiu_AutoReply/tree/7698edb87567d8a5b0e78a9dbd28df235442b38d),此分支将会不时从[上游仓库](https://github.com/0honus0/CaoLiu_AutoReply/)同步更新。
注:当前分支基于 [0honus0/CaoLiu_AutoReply at 708c2d277c17277411eb120d43e0c2fbb4146c09](https://github.com/0honus0/CaoLiu_AutoReply/tree/708c2d277c17277411eb120d43e0c2fbb4146c09),此分支将会不时从[上游仓库](https://github.com/0honus0/CaoLiu_AutoReply/)同步更新。

### 更新日志

```
2023.07.20-Based-0.23.07.01.1
从上游仓库同步更新,Commit:“更新版本号”
修复在获取已回复帖子列表时无法识别置顶帖(绿色链接)的问题
注:更新了config.example.yml
2023.07.02-Based-0.23.07.01.1
从上游仓库同步更新,Commit:“增加回复板块选择,修改登陆参数”
更新了config.example.yml
Expand Down Expand Up @@ -35,6 +40,8 @@

### 腾讯云函数配置

由于国内节点经常屏蔽社区域名,建议使用海外节点创建云函数。

- 创建一个云函数,选择“从头开始”创建。

- 运行环境:设为 `Python 3.6``Python 3.7`
Expand All @@ -53,12 +60,19 @@

- 执行超时时间:请按照实际运行时间设定,应略大于实际运行时间。红框是因为未启用异步执行。

- 计算执行超时时间:在`config.yml`文件内寻找参数`TimeIntervalEnd`(时间间隔最大值)执行超时时间应大于该参数的值*11,如`TimeIntervalEnd: 2048`,那么执行超时时间应大于`(2048+5)*11`,即`22583`,这是比较稳妥的,可以避免因超时而云函数退出
- 计算执行超时时间:在`config.yml`文件内寻找参数`TimeIntervalEnd`(时间间隔最大值),执行超时时间应大于该参数加上`PollingTime`(循环间隔)之和乘以`ReplyLimit`(回复次数限制)加上1之和的值

- 需要注意的是,由于开启异步执行后,云函数超时时间最大值为`86400`秒,所以`TimeIntervalEnd`的值不应大于`7849`
- 具体公式为:`(TimeIntervalEnd + PollingTime) * (ReplyLimit + 1)`

-`TimeIntervalEnd: 2048`,那么执行超时时间应大于`(2048+5)*11`,即`22583`,这是比较稳妥的,可以避免因超时而云函数退出。

- 为了便于计算,现已加入执行超时时间计算器`ExecutionTimeoutCalculator.py`可使用它快速计算

![image-20230720211140098](https://s2.loli.net/2023/07/20/XVYTS8baLwxh3c7.png)

- 需要注意的是,由于开启异步执行后,云函数超时时间最大值为`86400`秒,所以`TimeIntervalEnd`的值不应大于`7849`

![image-20230411220418260](https://s2.loli.net/2023/04/11/IDLkK2JBTPOAMoe.png)
![image-20230411220418260](https://s2.loli.net/2023/04/11/IDLkK2JBTPOAMoe.png)

- 日志配置:可不配置日志

Expand Down
2 changes: 1 addition & 1 deletion config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ gobal_config:
#回复内容
ReplyContent: ['感谢分享','感谢你的分享','谢谢分享','多谢分享','感谢作者的分享','谢谢坛友分享','感谢聚聚的分享','感谢楼主分享','内容精彩','很棒的内容','不错不错','不错,点赞了','涨见识了','很有意思','给您点个赞','内容很丰富','有点意思','值得收藏']
#关键字屏蔽,主要防止签到贴
ForbidContent: ['签到','专用贴','禁止无关回复','技术区大乐透']
ForbidContent: ['签到','专用贴','禁止无关回复','技术区大乐透','领奖','禁言']
#使用proxy
Proxy: False
Proxies:
Expand Down
6 changes: 3 additions & 3 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import logging.config ,sys
from sendLog import sendLog

__verison__ = "2023.07.02-Based-0.23.07.01.1"
__verison__ = "2023.07.20-Based-0.23.07.03.1"

def outputLog(projectName):
log = logging.getLogger(f"{projectName}")
Expand Down Expand Up @@ -374,7 +374,7 @@ def get_personal_posted_list(self):
sleep(2)
res = requests.get(self.Personal_posted , headers = self.Headers , cookies = self.cookies, proxies = proxies)
content = res.text
posted_pat_title_rule : str = '<a[^>]+class="a2">([^<]+)'
posted_pat_title_rule : str = '<a[^>]+class="a2">(?:<font[^>]+>)?([^<]+)(?:<\/font>)?<\/a>'
posted_pat_title = re.findall(posted_pat_title_rule, content)
self.excludeContent.extend(posted_pat_title)

Expand Down Expand Up @@ -599,7 +599,7 @@ def checkHosts():
log.info(f"检查 {i} :能访问")
except requests.exceptions.ConnectionError:
log.info(f"检查 {i} :不能访问")
sendLog('CaoLiu_AutoReply')
sendLog('CaoLiu_AutoReply', ' - 调试模式')

def main_handler(event, context):
if DebugMode:checkHosts()
Expand Down

0 comments on commit e94987f

Please sign in to comment.