zoukankan      html  css  js  c++  java
  • 超星自动签到并邮件通知

    import requests,json,time,datetime
    import smtplib
    from email.mime.text import MIMEText
    from email.header import Header
     
    mail_host="smtp.qq.com"#设置的邮件服务器host必须是发送邮箱的服务器,与接收邮箱无关。
    mail_user=""#qq邮箱登陆名
    mail_pass="" #开启stmp服务的时候并设置的授权码,注意!不是QQ密码。
     
    sender=''#发送方qq邮箱
    receivers=['']#接收方qq邮箱
    
    
    username='17628678646'#账号
    passwd='xiaoxinxingshi5'#密码
    #server酱推送
    SCKEY=''
    #设置轮询间隔(单位:秒,建议不低于5)
    speed=10
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36'}
    
    
    coursedata=[]
    activeList=[]
    course_index=0
    status=0
    activates=[]
    a=1
    index=0
    
    def login(username,passwd): #获取cookie
        url='https://passport2-api.chaoxing.com/v11/loginregister'
        data={'uname':username,'code':passwd,}
        session = requests.session()
        cookie_jar = session.post(url=url, data=data, headers=headers).cookies
        cookie_t = requests.utils.dict_from_cookiejar(cookie_jar)
        return cookie_t
    
    cookie=login(username,passwd)
    uid=cookie['UID']
    
    def taskactivelist(courseId,classId):
        global a
        url="https://mobilelearn.chaoxing.com/ppt/activeAPI/taskactivelist?courseId="+str(courseId)+"&classId="+str(classId)+"&uid="+uid
        res=requests.get(url,headers=headers,cookies=cookie)
        respon = res.status_code
        if respon==200:#网页状态码正常
            data=json.loads(res.text)
            activeList=data['activeList']
            #print(activeList)
            for item in activeList:
                if("nameTwo" not in item):
                    continue
                if(item['activeType']==2 and item['status']==1):
                    signurl=item['url']#提取activePrimaryId
                    aid = getvar(signurl)
                    if(aid not in activates):
                        print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'[签到]',coursedata[i]['name'],'查询到待签到活动 活动名称:%s 活动状态:%s 活动时间:%s aid:%s'%(item['nameOne'],item['nameTwo'],item['nameFour'],aid))
                        sign(aid,uid)#print('调用签到函数')
                        
                        a=2
    
        else:
            print('error',respon)#不知道为啥...
    
    
    def getvar(url):
        var1 = url.split("&")
        for var in var1:
            var2 = var.split("=")
            if(var2[0]=="activePrimaryId"):
                return var2[1]
        return "ccc"  
    
    
    def sign(aid,uid):
        global status,activates
        url="https://mobilelearn.chaoxing.com/pptSign/stuSignajax?activeId="+aid+"&uid="+uid+"&clientip=&latitude=-1&longitude=-1&appType=15&fid=0"
        res=requests.get(url,headers=headers,cookies=cookie)
        push(SCKEY,res.text)
        if(res.text=="success"):
            try:
                message=MIMEText("用户:"+uid+" 签到成功!",'plain','utf-8')
                message['From']=Header("自动签到程式",'utf-8') #设置显示在邮件里的发件人
                message['To']=Header("自动程序收件人",'utf-8') #设置显示在邮件里的收件人
                subject ='自动签到程序脚本'
                message['Subject']=Header(subject,'utf-8') #设置主题和格式
                smtpobj=smtplib.SMTP_SSL(mail_host,465) #本地如果有本地服务器,则用localhost ,默认端口25,腾讯的(端口465或587)
                smtpobj.set_debuglevel(1)
                smtpobj.login(mail_user,mail_pass)#登陆QQ邮箱服务器
                smtpobj.sendmail(sender,receivers,message.as_string())#发送邮件
                print("用户:"+uid+" 签到成功!")
                smtpobj.quit()#退出
            except smtplib.SMTPException as e :
                print("Error:无法发送邮件")
                print(e)
            print("用户:"+uid+" 签到成功!")
            activates.append(aid)
            status=2
        else:
            print(res.text,'签到失败')  
            activates.append(aid)
    
    def push(SCKEY,msg):
        if SCKEY.isspace() or len(SCKEY)==0:
            return
        else:
            api = 'https://sc.ftqq.com/'+SCKEY+'.send'
            title = u"签到辣!"
            content = '课程: '+coursedata[i]['name']+'
    
    签到状态:'+msg
            data = {
               "text":title,
               "desp":content
            }
            req = requests.post(api,data = data)        
    
    
    url="http://mooc1-api.chaoxing.com/mycourse/backclazzdata?view=json&rss=1"
    res=requests.get(url,headers=headers,cookies=cookie)
    cdata=json.loads(res.text)
    if(cdata['result']!=1):
        print("课程列表获取失败")
    for item in cdata['channelList']:
        if("course" not in item['content']):
            continue
        pushdata={}
        pushdata['courseid']=item['content']['course']['data'][0]['id']
        pushdata['name']=item['content']['course']['data'][0]['name']
        #pushdata['imageurl']=item['content']['course']['data'][0]['imageurl']
        pushdata['classid']=item['content']['id']
        coursedata.append(pushdata)
    print("获取成功:")
    
    for item in coursedata:#打印课程
            print(str(index)+".课程名称:"+item['name'])
            index+=1
            
    while 1:
        for i in range(index):
            time.sleep(speed)#休眠
            taskactivelist(coursedata[i]['courseid'],coursedata[i]['classid'])
            if a==2:
                a=0
            else:           
                print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'),'[监控运行中]课程:',coursedata[i]['name'],'未查询到签到活动')  
    

      基于GitHub某仓库代码改的,现在由于找不到原地址在哪儿了。所以若发现侵权,请联系我删除!

  • 相关阅读:
    【prufer编码】BZOJ1430 小猴打架
    【费马小定理】BZOJ3260 跳
    【欧拉函数】BZOJ2705: [SDOI2012]Longge的问题
    【卡特兰数】BZOJ1485: [HNOI2009]有趣的数列
    【缩点+拓扑判链】POJ2762 Going from u to v or from v to u?
    【Floyd】BZOJ1491: [NOI2007]社交网络
    【转】对信息学竞赛中调试方法的建议
    【建图+拓扑判环】BZOJ3953: [WF2013]Self-Assembly
    【dfs判负环】BZOJ1489: [HNOI2009]最小圈
    【二分+最小树形图】UVA11865 比赛网络
  • 原文地址:https://www.cnblogs.com/misubishi/p/13221990.html
Copyright © 2011-2022 走看看