这pytest也太奇怪了吧
This commit is contained in:
7
.idea/CourseInformer.iml
generated
7
.idea/CourseInformer.iml
generated
@@ -4,10 +4,11 @@
|
|||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Python 3.13 virtualenv at ~/PycharmProjects/CourseInformer/.venv" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 3.13" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PackageRequirementsSettings">
|
<component name="PyDocumentationSettings">
|
||||||
<option name="versionSpecifier" value="大于或等于 (>=x.y.z)" />
|
<option name="format" value="GOOGLE" />
|
||||||
|
<option name="myDocStringFormat" value="Google" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -25,11 +25,12 @@ curl -s -o /dev/null -X POST http://127.0.0.1:3000/send_private_msg \
|
|||||||
定义方法publish_info负责推送,该类只暴露publish_info方法,如果涉及其他方法以及字段,均需要以`_`开头进行私有化
|
定义方法publish_info负责推送,该类只暴露publish_info方法,如果涉及其他方法以及字段,均需要以`_`开头进行私有化
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import os
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import json
|
|
||||||
import requests
|
import requests
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
31
main.py
31
main.py
@@ -42,12 +42,11 @@
|
|||||||
通知将在合适时间发送,可使用时间轮算法完成周、日的课程安排,但需要先对reader返回的课程时间进行解析。该脚本将持续运行并检测安排,在合适的时间发送通知
|
通知将在合适时间发送,可使用时间轮算法完成周、日的课程安排,但需要先对reader返回的课程时间进行解析。该脚本将持续运行并检测安排,在合适的时间发送通知
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import time
|
|
||||||
import datetime
|
import datetime
|
||||||
from typing import List
|
import time
|
||||||
import reader
|
|
||||||
import informer
|
|
||||||
|
|
||||||
|
import informer
|
||||||
|
import reader
|
||||||
|
|
||||||
# 课程时间安排
|
# 课程时间安排
|
||||||
CLASS_SCHEDULE = {
|
CLASS_SCHEDULE = {
|
||||||
@@ -102,7 +101,7 @@ def _get_current_week(start_date: datetime.date = datetime.date(2025, 8, 25)) ->
|
|||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
delta = today - start_date
|
delta = today - start_date
|
||||||
week = delta.days // 7 + 1
|
week = delta.days // 7 + 1
|
||||||
return max(week, 1) # 确保至少为第1周
|
return week # 确保至少为第1周
|
||||||
|
|
||||||
|
|
||||||
def _get_notification_time(period: str, timeslot_from: int) -> str:
|
def _get_notification_time(period: str, timeslot_from: int) -> str:
|
||||||
@@ -290,37 +289,37 @@ def _test_day_notifications(courses, current_week: int, current_day: str, day_na
|
|||||||
# _send_course_notification(course, course.period)
|
# _send_course_notification(course, course.period)
|
||||||
|
|
||||||
|
|
||||||
def test_notification_logic():
|
def _test_notification_logic():
|
||||||
"""测试方法:模拟第一周第一天、第二天、第三天的课程安排通知逻辑"""
|
"""测试方法:模拟第一周第一天、第二天、第三天的课程安排通知逻辑"""
|
||||||
print("开始测试通知逻辑...")
|
print("开始测试通知逻辑...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 读取课程信息
|
# 读取课程信息
|
||||||
student_info, courses = reader.read_course_schedule()
|
student_info, courses = reader.read_course_schedule()
|
||||||
print(f"已读取 {len(courses)} 门课程信息")
|
print(f"已读取 {len(courses)} 门课程信息")
|
||||||
|
|
||||||
# 模拟第一周
|
# 模拟第一周
|
||||||
current_week = 1
|
current_week = 1
|
||||||
print(f"模拟第 {current_week} 周")
|
print(f"模拟第 {current_week} 周")
|
||||||
|
|
||||||
# 测试第一天(星期一)
|
# 测试第一天(星期一)
|
||||||
_test_day_notifications(courses, current_week, "星期一", "第一天(星期一)")
|
_test_day_notifications(courses, current_week, "星期一", "第一天(星期一)")
|
||||||
|
|
||||||
# 测试第二天(星期二)
|
# 测试第二天(星期二)
|
||||||
_test_day_notifications(courses, current_week, "星期二", "第二天(星期二)")
|
_test_day_notifications(courses, current_week, "星期二", "第二天(星期二)")
|
||||||
|
|
||||||
# 测试第三天(星期三)
|
# 测试第三天(星期三)
|
||||||
_test_day_notifications(courses, current_week, "星期三", "第三天(星期三)")
|
_test_day_notifications(courses, current_week, "星期三", "第三天(星期三)")
|
||||||
|
|
||||||
print("\n测试完成")
|
print("\n测试完成")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"测试过程中出错: {e}")
|
print(f"测试过程中出错: {e}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 运行测试方法
|
# 运行测试方法
|
||||||
test_notification_logic()
|
# _test_notification_logic()
|
||||||
|
|
||||||
# 如果要运行主方法,取消下面的注释
|
# 如果要运行主方法,取消下面的注释
|
||||||
# main()
|
main()
|
||||||
@@ -2,10 +2,11 @@
|
|||||||
Module for reading course schedule information from HTML file
|
Module for reading course schedule information from HTML file
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from dataclasses import dataclass
|
|
||||||
from typing import List
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
beautifulsoup4>=4.13.4
|
|
||||||
requests>=2.32.5
|
|
||||||
Reference in New Issue
Block a user