吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1154|回复: 26
上一主题 下一主题
收起左侧

[Python 原创] 统计人数和未到家名单(适用于老师)已更新!

[复制链接]
跳转到指定楼层
楼主
qqy123 发表于 2024-12-14 13:25 回帖奖励
本帖最后由 qqy123 于 2024-12-20 22:29 编辑

用于老师统计学生到家情况。

exe文件:https://wwad.lanzn.com/iaOLi2i39coj
exe更新版:https://wwad.lanzn.com/ix7u42imh9cb

效果图:

更新版效果图:(无)

源码:
[Python] 纯文本查看 复制代码
import os
import re
import tkinter as tk
from tkinter import messagebox, scrolledtext
from tkinter import filedialog
from wxauto import WeChat

config_dir = os.path.join(os.getcwd(), 'config')
custom_message_path = os.path.join(config_dir, 'custom_wechat_message.txt')

def create_file_if_not_exists(directory, filename):
    file_path = os.path.join(directory, filename)
    if not os.path.exists(file_path):
        with open(file_path, 'w', encoding='utf-8') as f:
            pass

def extract_names(text):
    pattern = re.compile(r'[\u4e00-\u9fff]{1,4}')
    return set(pattern.findall(text))

def open_file(filename):
    try:
        os.startfile(filename)
    except Exception as e:
        messagebox.showerror("错误", f"无法打开文件: {e}")

def show_description():
    description = (
        "班级名单\n"
        "    填写方式:“=”前为真名,“=”后为微信名。\n"
        "    示例:\n"
        "    冯子洋=@冯子洋(13647692406) √\n"
        "    冯军杰=冯军杰187852309\n\n"
        "微信班级群名\n"
        "    填写微信群名,用于发送信息,请确保微信已登录。\n"
        "    示例:23计算机网络技术班\n\n"
        "已报名单\n"
        "    只能填写真名,且一行一个名字。\n\n"
        "自定义微信信息\n"
        "    可以自定义@后边的信息。\n"
    )
    desc_window = tk.Toplevel()
    desc_window.title("说明")
    text_area = scrolledtext.ScrolledText(desc_window, wrap=tk.WORD, width=60, height=20)
    text_area.insert(tk.INSERT, description)
    text_area.pack(padx=10, pady=10)
    text_area.config(state='disabled')

def open_settings():
    settings_window = tk.Toplevel(root)
    settings_window.title("设置")
    settings_window.geometry("400x300")


    buttons = [
        ("班级名单", "班级名单.txt"),
        ("已报名单", "已报名单.txt"),
        ("微信班级群名", "微信班级群名.txt"),
        ("自定义微信信息", "custom_wechat_message.txt"),
        ("说明", None)
    ]

    for btn_text, file_name in buttons:
        btn = tk.Button(settings_window, text=btn_text, width=20, command=lambda f=file_name: open_file_button(f))
        btn.pack(pady=5)

def open_file_button(file_name):
    if file_name:
        file_path = os.path.join(config_dir, file_name)
        if not os.path.exists(file_path):
            create_file_if_not_exists(config_dir, file_name)
        open_file(file_path)
    else:
        show_description()

def show_about():
    about_window = tk.Toplevel(root)
    about_window.title("关于")
    about_window.geometry("400x150")

    # 创建标签并设置字体颜色为蓝色以模拟链接样式
    link_label = tk.Label(about_window, text="吾爱破解论坛", fg="blue", cursor="hand2", font=("Arial", 14, "underline"))
    link_label.pack(pady=20)

    # 定义点击链接时打开网页的函数
    def open_link(event):
        import webbrowser
        webbrowser.open("https://www.52pojie.cn/")

    # 绑定鼠标点击事件到标签
    link_label.bind("<Button-1>", open_link)

def check_unenrolled():
    class_list_path = os.path.join(config_dir, '班级名单.txt')
    enrolled_list_path = os.path.join(config_dir, '已报名单.txt')

    # 读取班级名单
    class_names = {}
    with open(class_list_path, 'r', encoding='utf-8') as f:
        for line in f:
            line = line.strip()
            if not line:
                continue
            if '=' in line:
                real_name, wechat_name = line.split('=', 1)
                real_name = real_name.strip()
                wechat_name = wechat_name.strip()
                class_names[real_name] = wechat_name
            else:
                real_name = line.strip()
                class_names[real_name] = real_name  # 默认微信名与真名相同

    # 读取已报名单
    enrolled_names = set()
    with open(enrolled_list_path, 'r', encoding='utf-8') as f:
        for line in f:
            extracted = extract_names(line)
            enrolled_names.update(extracted)

    # 计算未报名名单
    not_enrolled = set(class_names.keys()) - enrolled_names
    total = len(class_names)
    enrolled = len(enrolled_names)
    not_enrolled_count = len(not_enrolled)

    # 显示统计信息
    stats = f"总人数:{total}\n已报人数:{enrolled}\n未报人数:{not_enrolled_count}"
    messagebox.showinfo("统计信息", stats)

    # 显示未报名名单
    if not not_enrolled:
        messagebox.showinfo("结果", "所有学生都已报名。")
        return

    # 每行显示7个名字
    not_enrolled_text = "\n".join([", ".join(sorted(not_enrolled)[i:i+7]) for i in range(0, len(sorted(not_enrolled)), 7)])
    messagebox.showinfo("未报名名单", not_enrolled_text)

def send_reminder():
    # 读取自定义微信信息
    if not os.path.exists(custom_message_path):
        create_file_if_not_exists(config_dir, 'custom_wechat_message.txt')
        custom_message = ",你们家长还没有反馈你们到家情况。"
    else:
        with open(custom_message_path, 'r', encoding='utf-8') as f:
            custom_message = f.read().strip()

    # 读取班级名单和已报名单
    class_list_path = os.path.join(config_dir, '班级名单.txt')
    enrolled_list_path = os.path.join(config_dir, '已报名单.txt')

    # 读取班级名单
    class_names = {}
    with open(class_list_path, 'r', encoding='utf-8') as f:
        for line in f:
            line = line.strip()
            if not line:
                continue
            if '=' in line:
                real_name, wechat_name = line.split('=', 1)
                real_name = real_name.strip()
                wechat_name = wechat_name.strip()
                class_names[real_name] = wechat_name
            else:
                real_name = line.strip()
                class_names[real_name] = real_name  # 默认微信名与真名相同

    # 读取已报名单
    enrolled_names = set()
    with open(enrolled_list_path, 'r', encoding='utf-8') as f:
        for line in f:
            extracted = extract_names(line)
            enrolled_names.update(extracted)

    # 计算未报名名单
    not_enrolled = set(class_names.keys()) - enrolled_names
    if not not_enrolled:
        messagebox.showinfo("结果", "所有学生都已报名。")
        return

    # 构建消息内容
    message = ""
    for name in sorted(not_enrolled):
        wechat_name = class_names.get(name, name)  # 如果没有微信名,则使用真名
        message += f"@{wechat_name} "
    message += custom_message

    # 读取微信班级群名
    contact_list_path = os.path.join(config_dir, '微信班级群名.txt')
    with open(contact_list_path, 'r', encoding='utf-8') as f:
        contact_name = f.read().strip()

    if not contact_name:
        messagebox.showerror("错误", "微信班级群名.txt 中没有联系人信息!")
        return

    # 发送消息
    try:
        wx = WeChat()
        wx.SendMsg(message, contact_name)
        messagebox.showinfo("结果", "消息已发送。")
    except Exception as e:
        messagebox.showerror("错误", f"发送消息失败: {e}")

root = tk.Tk()
root.title("检查程序")
root.geometry("400x350")

label = tk.Label(root, text="检查程序", font=("Arial", 16))
label.pack(pady=10)

frame = tk.Frame(root)
frame.pack(pady=10)

settings_btn = tk.Button(frame, text="设置", width=10, command=open_settings)
settings_btn.pack(side=tk.LEFT, padx=10)

about_btn = tk.Button(frame, text="关于", width=10, command=show_about)
about_btn.pack(side=tk.RIGHT, padx=10)

unenrolled_label = tk.Label(root, text="未报名单:", font=("Arial", 12))
unenrolled_label.pack(pady=5)

check_btn = tk.Button(root, text="检查", width=10, command=check_unenrolled)
check_btn.pack(pady=5)

remind_btn = tk.Button(root, text="提醒", width=10, command=send_reminder)
remind_btn.pack(pady=5)

root.mainloop()

免费评分

参与人数 4吾爱币 +9 热心值 +3 收起 理由
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
blywq + 1 + 1 谢谢@Thanks!
wuloveyou + 1 我很赞同!
Rain39 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

推荐
hhh223 发表于 2024-12-14 19:01
等当老师了再用
推荐
netdna518 发表于 2024-12-15 08:37
再给楼主提个建议呗:使用TXT文件录入,不如excel表格,读取excel表格,标红的就是需要群里面艾特的,这样效率会提高很多倍
头像被屏蔽
沙发
pomxion 发表于 2024-12-14 13:47
3#
xzy85766828 发表于 2024-12-14 13:58
来晚啦...文件取消分享了
4#
xyFan 发表于 2024-12-14 14:41
现在当老师的都这么卷了
5#
wuloveyou 发表于 2024-12-14 15:21
支持一波小创作   感谢楼主分享~~~
6#
 楼主| qqy123 发表于 2024-12-14 15:23 |楼主
xzy85766828 发表于 2024-12-14 13:58
来晚啦...文件取消分享了

并没有,我这里访问正常。
7#
happyplay 发表于 2024-12-14 17:24
感谢分享!学习一下。
8#
han163426 发表于 2024-12-14 18:23
这也太卷了吧,带头卷起来
9#
cai2532 发表于 2024-12-14 18:35
这个不错,很实用。
10#
skzhaixing 发表于 2024-12-14 18:43
看看是个什么东西
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-1-6 01:06

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表