Python-- achieve automatic real-time monitoring network class attendance, punch card

First delighted the audience grandpa can turn on this blog, generally have most of them are students interested in this post, I'm a student, so affirm what I write is not charged, followed by the code I have posted It is free, without any profit, there is a need can be reproduced, but do not get the code to make money.
I hope you fit!

HaoXuan
Closed in response to the national call to stop school, students are beginning to teach online, but because of course many, the message is complicated, often miss class attendance for this problem, as the main blog Python fan, fully using the Python language to write this blog , hoping to help small partners to complete the school attendance problems (Note: just to help you sign in, rather than tell you to sign on behalf of my starting point is to help memory is not very good student attendance, to prevent leakage sign named teacher), so I hope everyone bloggers can understand the pains.
fafa
Man of few words said, and offered two renderings
Gets Timetable
real time monitoring
into the formal tutorials

①Python environment

Python3.6及以上版本,需要配备的库requests,json,time
代码运行软件:Pycharm

**

② manually log

Manual login Address: http://mooc1-api.chaoxing.com/mycourse/backclazzdata?view=json&rss=1

**
log in

③Cookie get

The most basic check-in process is the user of Cookie, the equivalent of the user's identity, originally written in the Python version, I will direct my own Cookie as a parameter stored in the code, but after tests found Since each user Cookie error after so different, so hard small partners to manually obtain personal Cookie, put the code in detail Cookie acquisition process as shown below
Note: right after the completion of the audit log in the elements, you can come to this page
Here Insert Picture Description
to copy the value of their Cookie Add the following code

#填入Cookie
headers={
  "Cookie": "",
  "User-Agent": "Mozilla/5.0 (iPad; CPU OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 ChaoXingStudy/ChaoXingStudy_3_4.3.2_ios_phone_201911291130_27 (@Kalimdor)_11391565702936108810"
}

After Cookie values are placed well, the rest do not need to modify the code can be used directly, if you have questions about the code or good advice I can feel free to comment District dd
Due to relatively recent heavy task of learning, the rest of the code does not do more to explain, directly offer, loving little programming partners can think for themselves about the process
complete code offer (Note: Cookie value from the meeting)

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2020/3/5 13:19
# @Author  : HaoXuan
# @Email   : [email protected]
# @File    : 超星学习通实时签到监控.py
# @Software: PyCharm
import requests
import json
import time

#填入Cookie
headers={
  "Cookie": "",
  "User-Agent": "Mozilla/5.0 (iPad; CPU OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 ChaoXingStudy/ChaoXingStudy_3_4.3.2_ios_phone_201911291130_27 (@Kalimdor)_11391565702936108810"
}
#填入uid
uid=""
coursedata=[]
activeList=[]
course_index=0
speed=10
status=0
status2=0
activates=[]
def backclazzdata():
    global coursedata
    url="http://mooc1-api.chaoxing.com/mycourse/backclazzdata?view=json&rss=1"
    res=requests.get(url,headers=headers)
    cdata=json.loads(res.text)
    if(cdata['result']!=1):
        print("请补充Cookie否则课程列表获取失败")
        return 0
    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("获取成功")  
    #print(coursedata)  
    printdata()

def printdata():
    global course_index,speed
    index=1
    for item in coursedata:
        print(str(index)+".课程名称:"+item['name'])
        index+=1
    course_index=int(input("请输入监控课程监控课程序号:"))-1
    print("监控课程设定完成")
    speed=int(input("请输入监控频率:")) #频率是监控的速度,一格10秒,适中选择就好
    print("监控频率设置完毕")
    res=input("输入666启动监控:")
    if(res=="start"):
        startsign()
    else:
        printdata    



def taskactivelist(courseId,classId):
    global activeList
    url="https://mobilelearn.chaoxing.com/ppt/activeAPI/taskactivelist?courseId="+str(courseId)+"&classId="+str(classId)+"&uid="+uid
    res=requests.get(url,headers=headers)
    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']
            aid = getvar(signurl)
            if(aid not in activates):
                print("【签到】查询到待签到活动 活动名称:%s 活动状态:%s 活动时间:%s aid:%s"%(item['nameOne'],item['nameTwo'],item['nameFour'],aid))
                sign(aid,uid)   

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)
    if(res.text=="success"):
        print("用户:"+uid+" 签到成功!")
        activates.append(aid)
        status=2
    else:
        print("签到失败")  
        activates.append(aid)  

def startsign():
    global status,status2
    status=1
    status2=1
    ind=1
    print("监控启动 监控课程为:%s 监控频率为:%s"%(coursedata[course_index]['name'],str(speed)))
    while(status!=0 and status2!=0):
        ind+=1
        taskactivelist(coursedata[course_index]['courseid'],coursedata[course_index]['classid'])
        time.sleep(speed)
        if(status==1):
            print(str(ind)+" [签到]监控运行中,未查询到签到活动")
        elif(status==2):
            print(str(ind)+" [新签到]监控运行中,未查询到签到活动")         
    print("任务结束")
    printdata()

backclazzdata()

The principle is very simple, we are interested in what can be achieved yourself, if you want to learn, you can peruse a Python code, interested private letter I can, I will use API and package python code sent to you (Python Code no increase landing module, the ability of their own can achieve it)
Thank you!
HaoXuan
Finally, talk about this a sign automatic real-time monitoring software can monitor a course, but can open up multi-course monitor
then, the code to meet the ordinary sign, pick up the check-in, check-position (position information gaps), does not support photo sign (hope and cattle can solve this problem) because the program is not perfect, but if you fail you may be prompted to learn through opening the inquiry, it is a sign has been completed.
HaoXuan
If you have Python fans, welcome to my attention on the blog, we can explore together, join forces big learning Python: Life is short, I learned Python!

@Author:HaoXuan

Released nine original articles · won praise 18 · views 2020

Guess you like

Origin blog.csdn.net/kangqiao0422/article/details/104768092