网课必备,自动入会

需求分析

Anyiya在上网课的日子里表现的十分懒惰,被叫醒时通常耳边还回荡着室友的呼唤:"anyi上课了!",已知anyi大部分课程老师都会使用腾讯会议,然后迷迷糊糊的小anyi总是在思考该进入哪一个会议号的过程中造成晚点现象。乐于用计算机解决问题的anyi决定手写一个脚本帮助自己进入该进入的腾讯会议。

设计思路

1.通过pymouse获取腾讯会议程序的坐标,模拟鼠标双击,打开腾讯会议
2.休眠三秒后,获取进入会议坐标,单击进入会议
3.获取系统时间,确定当前是周几、以及时分数
4.从设置好的固定课表文档匹配,根据星期数照应,按照时分数找到最近的一节课程会议号,并记录该会议是否有密码,如果有密码获取会议密码
5.通过pykeyboard模拟键盘粘贴会议号,回车进入会议

代码展示

import tkinter as tk
from tkinter import ttk, messagebox as msg
import pymouse, pykeyboard, pyperclip,time
from pynput.mouse import Button,Controller as mouse_cl
from pynput.keyboard import Key,Controller as key_cl
import datetime

# 获取系统时间
curr_time = datetime.datetime.now()
week = datetime.date(curr_time.year, curr_time.month, curr_time.day).weekday() + 1
hour = curr_time.hour
minu =curr_time.minute

# =============================================================================
# # 创建用户窗口
# mainForm = tk.Tk()
# mainForm.title('腾讯会议')
# mainForm.resizable(0, 0)
# mainForm.iconbitmap("./ico.ico")
# 
# # 内容定制框,获取鼠标指针、会议信息;
# nameText = tk.Text(mainForm, height=10, width=40)
# nameText.insert(0.0, "会议列表输入这里")
# nameText.grid(row=0, padx=5, pady=5)
# 
# mousepoint = tk.Text(mainForm, height=10, width=40)
# mousepoint.insert(0.0, "获取坐标输入这里")
# mousepoint.grid(row=1, padx=5, pady=5)
# =============================================================================

nameContent = "格式:星期(1-7表示)-小时(24H制)-分钟-会议号-(有密码?1:0)-密码(如无密码随机输入)"
#eg:nameContent = "1-7-40-0000000000-0-0000" 即表示周一早上七点四十会议号为0000000000且没有密码的会议
mouseSearchXY = (-1, -1)
mouseInputXY = (-1, -1)

# =============================================================================
# def onClickMouseButton():
#     global mouseStartXY, mouseInXY,mouseInputXY,mousePsword
#     m = pymouse.PyMouse()
#     msg.showinfo('提示', '请在点击确认后2秒内将鼠标移动腾讯会议,2秒后自动获取鼠标位置。')
#     time.sleep(2)
#     mouseStartXY = m.position()
#     x1,y1 = mouseStartXY[0], mouseStartXY[1]
#     msg.showinfo('提示', '请在点击确认后2秒内将鼠标移动加入会议,2秒后自动获取鼠标位置。')
#     time.sleep(2)
#     mouseInXY = m.position()
#     x2,y2 = mouseInXY[0], mouseInXY[1]
#     msg.showinfo('提示', '请在点击确认后2秒内将鼠标移动到会议号输入框,2秒后自动获取鼠标位置。')
#     time.sleep(2)
#     mouseInputXY = m.position()
#     x3,y3 = mouseInputXY[0], mouseInputXY[1]
#     msg.showinfo('获取坐标',' ',x1,y1,' ',x2,y2,' ',x3,y3)
# 
# 
# mouseButton = ttk.Button(mainForm, text='点击获取鼠标位置', width=40, command=onClickMouseButton)
# mouseButton.grid(row=3, padx=5, pady=5)
# =============================================================================


def onClickStartButton():
    # 可取消注释根据弹窗引导确定这三个坐标位置
    mouseStartXY = (35, 326)
    mouseInXY = (508, 171)
    mouseInputXY = (571, 127)
# =============================================================================
#     if mouseStartXY == (-1, -1) or mouseInXY == (-1, -1) or mouseInputXY == (-1, -1):
#         msg.showerror('错误', '请先获取鼠标位置')
#         return
#     # 判断输入框有没有内容
#     nameContent = nameText.get(0.0, tk.END).rstrip()
#     if nameContent == '':
#         msg.showerror('错误', '请先输入正确的会议名单')
#         return
#     # 开始
#     if not msg.askokcancel('提示', '提示完成之前别动鼠标哦'):
#         return
# =============================================================================
    lst = nameContent.split('\n')
    for i in lst:
        tweek,thour,tmin,ttxt,tf,tpswod = i.split('-')
        if str(tweek) != str(week):
            continue
        if int(hour) > int(thour):
            continue
        if int(minu) > int(tmin):
            continue
        m = pymouse.PyMouse()  # 获取鼠标对象
        m.click(mouseStartXY[0], mouseStartXY[1]) #模拟点击
        m.click(mouseStartXY[0], mouseStartXY[1])
        time.sleep(4) #等待腾讯会议打开时间
        m.click(mouseInXY[0], mouseInXY[1])
        mouse = mouse_cl()
        mouse.press(Button.left)
        mouse.release(Button.left)
        time.sleep(0.5)
        m.click(mouseInputXY[0], mouseInputXY[1])
        key = key_cl()
        key.type(ttxt)
        key.press(Key.enter)
        key.release(Key.enter)
        if tf=='1':   #如果有密码输入密码
            time.sleep(0.8)
            key = key_cl()
            key.type(tpswod)
            key.press(Key.enter)
            key.release(Key.enter)
        break

# =============================================================================
# startButton = ttk.Button(mainForm, text='启动', width=40, command=onClickStartButton)
# startButton.grid(row=4, padx=5, pady=5)
# =============================================================================

#mainForm.mainloop()

onClickStartButton()

延展任务

1.提高内聚降低耦合,为用户设计获取鼠标位置的脚本。
2.通过本地txt文档获取鼠标位置以及会议列表,使程序得以泛用。

posted @ 2022-04-24 16:58  anyiya  阅读(956)  评论(0编辑  收藏  举报