AI摘要:本文介绍了通过Python脚本实现课表信息推送的方法。用户需手动导入课表数据到脚本,并借助qmsg推送服务每日发送通知。文章提供了课程表、时间段信息以及课表推送的完整代码。代码中包含了定义Qmsg发送函数、获取当前日期及时间段、解析周数和判断课程是否在指定范围内等功能。用户需自行修改个人信息,如qmsg_key和qq_number,以实现自动化的课表提醒。具体代码及实现依赖的工具和库列表链接在GitHub上提供。

Powered by 返回门户.

需要手动导入自己的课表信息

找个定时软件按时户动pY脚本,这个也是 qmsg推送服务,哈哈,可以看的出,我好多都用它了,其是还是方便,Wechat的有限制,所以还是qmsg的好
具体地址:

import datetime
import requests

Qmsg 发送函数

def send_qmsg通知(qmsg_key, qq_number, msg):

postdata = {
    'msg': msg,
    'qq': qq_number
}
response = requests.post(f'https://qmsg.zendee.cn/send/{qmsg_key}', data=postdata)
if response.status_code == 200:
    print("通知已发送到QQ。")
else:
    print(f"通知发送失败,错误码:{response.status_code},响应内容:{response.text}")

课程表和时间段信息

course_schedule = {

1: [("编译原理", "第一节~第二节", "3号楼2030202", "1~18周"),
    ("编译原理实验", "第三节~第四节", "6号楼2060302", "1~18周"),
    ("人工智能", "第六节~第八节", "3号楼2030202", "1~15周"),
    ("人工智能", "第九节~第十节", "6号楼2060302", "4~12周")],
2: [("软件设计与体系结构实验", "第九节~第十节", "6号楼2060302", "1~18周"),
    ("软件设计与体系结构", "第六节~第八节", "3号楼2030202", "1~18周"),
    ("软件需求分析与建模", "第三节~第五节", "3号楼2030202,6号楼2060302", "1~18周")],
3: [("计算机网络", "第三节~第四节", "3号楼2030203", "1~18周"),
    ("软件应用开发实践", "第一节~第二节", "6号楼2060302", "1~18周")],
4: [("音乐鉴赏", "第九节~第十节", "1号楼2010404", "1~9周"),
    ("经济学原理", "第六节~第七节", "1号楼2010501", "1~18周"),
    ("计算机网络实验", "第三节~第四节", "6号楼2060201", "1~18周"),
    ("计算机网络", "第一节~第二节", "3号楼2030203", "1~18周")],
5: [("人机界面设计", "第三节~第五节", "2号楼2020103,6号楼2060101", "1~18周"),
    ("大学生职业生涯规划与就业指导(III)", "第一节~第二节", "1号楼2010506", "10~18周")],
6: [],  # 周六无课程
7: []   # 周日无课程

}

课程时间段

class_times = {

"第一节": ("08:00", "08:45"),
"第二节": ("08:50", "09:35"),
"第三节": ("09:50", "10:35"),
"第四节": ("10:40", "11:25"),
"第五节": ("11:30", "12:15"),
"第六节": ("14:30", "15:15"),
"第七节": ("15:20", "16:05"),
"第八节": ("16:10", "16:55"),
"第九节": ("17:00", "17:45"),
"第十节": ("17:50", "18:45")

}

start_date = datetime.date(2024, 9, 2)

def get_week_and_day(today):

delta_days = (today - start_date).days
week_number = (delta_days // 7) + 1
day_of_week = today.isoweekday()
return week_number, day_of_week

def parse_week_range(week_range):

week_range = week_range.replace("周", "")
return list(map(int, week_range.split('~')))

def is_course_active(course_week_range, week_number):

start_week, end_week = parse_week_range(course_week_range)
return week_number in range(start_week, end_week + 1)

def get_time_range(class_period):

start_class, end_class = class_period.split('~')
start_time = class_times[start_class][0]
end_time = class_times[end_class][1]
return f"{start_time}到{end_time}"

def get_start_time(class_period):

start_class = class_period.split('~')[0]
return class_times[start_class][0]

def get_todays_courses(today):

week_number, day_of_week = get_week_and_day(today)
courses = course_schedule.get(day_of_week, [])

if courses:
    # 按照课程的开始时间排序
    courses.sort(key=lambda course: get_start_time(course[1]))

if courses and courses[0][1].startswith("第一节"):
    course_info = "早八也要元气满满!\n\n"
else:
    course_info = "不是早八,美滋滋。\n\n"

course_info += f"今天是第 {week_number} 周,星期 {day_of_week}\n"
if courses:
    course_info += "今日课程安排:\n\n\n"
    for course in courses:
        if is_course_active(course[3], week_number):
            time_display = get_time_range(course[1])
            course_info += f"{course[0]} | 时间: {time_display} | 节次: {course[1]} | 地点: {course[2]}\n\n\n"
else:
    course_info += "今日无课程安排。"

return course_info.strip()

获取当前日期并发送当天的课程安排

today = datetime.date.today()
message = get_todays_courses(today)

Qmsg 发送示例

qmsg_key = ''
qq_number = ''
send_qmsg通知(qmsg_key, qq_number, message)


自行更改上述代码的信息

最后修改:2024 年 10 月 12 日
如果觉得我的文章挺有趣,赞赏一杯小奶茶
END
本文作者:
文章标题:写了一个课表推送,还不支持自己导入
本文地址:https://www.maxtral.fun/index.php/archives/41/
版权说明:若无注明,本文皆MAXBROSER原创,转载请保留文章出处。