python轮询+wingui32模块发送QQ消息

/ 0评 / 0

给一个很要好的朋友写的啦,她学校的教务系统服务器只要一选课就崩,一抢课就Server is busy,就想着用python写个脚本放在自己的服务器上,轮询教务系统,能进教务系统的时候就调用QQ发消息给她啦

# coding: utf-8
#Written by Aylmer
#Function: 轮询教务系统网站,状态码为200时通过QQ发送信息
#2020/9/29

import time
import sched
import requests
import win32gui
import win32con
import win32clipboard as w
import datetime

# to_who:qq消息接收人
# msg:需要发送的消息
to_who='高冷'
msg='可以开始选课啦!'
# 初始化scheduler类
s = sched.scheduler(time.time, time.sleep)
# 教务系统地址
url="http://sys-jiaowu.nsmc.edu.cn/"
# 当前时间
x = datetime.datetime.now()

def getText():
    w.OpenClipboard()
    d = w.GetClipboardData(win32con.CF_UNICODETEXT)
    w.CloseClipboard()
    return d

def setText(aString):
    w.OpenClipboard()
    w.EmptyClipboard()
    w.SetClipboardData(win32con.CF_UNICODETEXT, aString)
    w.CloseClipboard()

def send_qq(to_who, msg):
    setText(msg)
    qq = win32gui.FindWindow(None, to_who)
    win32gui.SendMessage(qq, 258, 22, 2080193)
    win32gui.SendMessage(qq, 770, 0, 0)
    win32gui.SendMessage(qq, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
    win32gui.SendMessage(qq, win32con.WM_KEYUP, win32con.VK_RETURN, 0)

def task():
    response=requests.get(url)
    print(response.status_code)
    httpcode=response.status_code
    if httpcode==200: 
        x = datetime.datetime.now()
        print(x,"可以开始选课啦!")
        send_qq(to_who, msg)
    else: 
        print("状态码:",str(httpcode),"服务器忙,还不能选课哦")


def perform(inc):
    s.enter(inc, 0, perform, (inc,))
    task()

# inc=延时时间
def main(inc=5):
    s.enter(0, 0, perform, (inc,))
    s.run()


if __name__ == "__main__":
    main()

发表评论

邮箱地址不会被公开。 必填项已用*标注