Nanxin hospital filling reminder -- solve troubles for dear Counselors

Prospect review:

After I finished the automatic filling, I watched the hard-working counselors urge the students who did not fill in again and again in the group, so I worried. Is there any way to help the counselors share the downward pressure?

Of course, because of encryption, we still use the method of locating elements to solve login!

from selenium import webdriver
import time
chrome = webdriver.ChromeOptions()
# chrome.add_argument('--headless') # The reason why the browser cannot be hidden is that an error will be reported if the element is not found after hiding
bro = webdriver.Chrome(options=chrome)
bro.maximize_window()
bro.get(url='https://cas.njcit.cn/login/loginservice=https%3A%2F%2Fi.njcit.cn%2FEIP%2Fuser%2Findex.htm')
time.sleep(3) # Appropriate pause to facilitate page loading elements
bro.find_element_by_xpath('//*[@id="userName"]').send_keys(username) # enter the account
bro.find_element_by_xpath('//*[@id="password"]').send_keys(password) # enter the password
bro.find_element_by_xpath('//[@ id = "root"] / span / div [4] / div [2] / div [1] / div / div / form / div [4] / button [1] '). Click() # to log in
time.sleep(8) # Appropriate pause to facilitate page loading elements

There was a problem when I went in   The page is embedded, and positioning elements does not have much effect

  

 

 

  When the 999 times I tried to locate elements didn't work, I decided to find another way and use the Counselor's cookie with the url to enter other pages

    with open('cookies_njcit.json', 'w')as f:
        f.write(json.dumps(bro.get_cookies()))
    bro.quit()

At this time, we need to grab the package to find the id of all functions of the page, so as to find  

Summary of students' personal temperature data

After our unremitting efforts, we finally found a suspicious part. When we copied his url and opened it, a surprise came! You can study what comes out. You won't release it here!

url = 'https://i.njcit.cn/EIP/nonlogin/visitor/getServicesByTarget.htm'
aoo = requests.get(url=url).json()
for boo in aoo:
    if boo['name'] == 'Summary of students' personal temperature data':
        return boo['id']

  The following ideas are the same. It should be noted that some URLs need to add sid, which can be handled by yourself

 

  The above is a screenshot of the program. When we enter the class number we need to view, the students' names will appear below!

Then there is the favorite push part!

    # # Punch in push 2.0
    result = aoo
    stu_dict = {}
    for i in result:
        if i[2] in stu_dict.keys():
            stu_dict[i[2]].append([i[0], i[1]])
        else:
            stu_dict[i[2]] = [[i[0], i[1]]]

    url = 'https://qmsg.zendee.cn/group/key'
    now = datetime.datetime.now()
    message = 'The list of students who have not clocked in today is as follows:' + '\n'
    for item in stu_dict:
        for student in stu_dict[item]:
            message = message + f'@at={student[1]}@({student[0]})\t'
        msg = {
            'msg': message + f'\n{now.hour} : {now.minute} : {now.second}',
            'qq': item
        }

        if len(str(item)) != 0:
            requests.post(url, params=msg)
            print(str(item) + '  Push succeeded')
            print(message)
        else:
            print(msg['msg'], 'Due to lack QQ Group cannot be pushed!')
        sleep(60)
        message = 'The list of students who have not clocked in today is as follows:' + '\n'
    # Push 2.0 is not recommended because it may affect students' attention to important messages in the group
    for boo in aoo:
        url = 'https://qmsg.zendee.cn/group/key'
        msg = {
            'msg': '@at=' + str(boo[1]) + '@' + '\n' + str(boo[0]) + '  classmate' + '\n' + 'Please punch in as soon as possible!!',
            'qq': str(boo[2])
        }
        requests.post(url, params=msg)
        print(str(boo[0]) + '  Push succeeded')
        sleep(5)

 

If you put it out alone, you may not understand it. There are still some mistakes in the push part. For example, when you don't have this classmate's QQ, you will push the message to all groups. Because you don't have much time recently, you don't bother to modify these. Capable students can modify them by themselves. If there is a good version, you also hope to share it with me!

 

  The format of data stored in the table is according to the picture, and the information cannot be wrong!

The complete code is as follows! Please take it yourself!

# encoding:utf-8
import re
import time
import json
import xlrd
import requests
from selenium import webdriver


# Get cookies
def cookies(jsond):
    e = []
    t = json.load(open(jsond))
    for j in t:
        e.append(j['name'] + '=' + j['value'])
    return '; '.join(e)


# Read excel file
def excel(xlsx):
    wb = xlrd.open_workbook(xlsx)  # Open Excel file
    sheet = wb.sheet_by_name('Sheet1')  # Get the worksheet by excel table name (rank)
    dat = {}
    for a in range(sheet.nrows):  # Read the contents of the table circularly (read one row of data at a time)
        cells = sheet.row_values(a)  # Each row of data is assigned to cells
        dat[cells[0]] = [cells[1], cells[2]]
    return dat


# The login part has to be convenient for selenium
def login(username, password):
    chrome = webdriver.ChromeOptions()
    # chrome.add_argument('--headless')
    bro = webdriver.Chrome(options=chrome)
    bro.maximize_window()
    bro.get(url='https://cas.njcit.cn/login/login?service=https%3A%2F%2Fi.njcit.cn%2FEIP%2Fuser%2Findex.htm')
    time.sleep(3)
    bro.find_element_by_xpath('//*[@id="userName"]').send_keys(username) # enter the account
    bro.find_element_by_xpath('//*[@id="password"]').send_keys(password) # enter the password
    bro.find_element_by_xpath('//*[@id="root"]/span/div[4]/div[2]/div[1]/div[1]/div/div/form/div[4]/button[1]').click()
    time.sleep(8)
    with open('cookies_njcit.json', 'w')as f:
        f.write(json.dumps(bro.get_cookies()))
    bro.quit()

# Summary page of students' personal temperature data
def sid():
    url = 'https://i.njcit.cn/EIP/nonlogin/visitor/getServicesByTarget.htm'
    aoo = requests.get(url=url).json()
    for boo in aoo:
        if boo['name'] == 'Summary of students' personal temperature data':
            return boo['id']


def blpcurl():
    url = 'https://i.njcit.cn/EIP//nonlogin/elobby/service/start.htm?sid=' + sid()
    aoo = requests.get(url=url).text
    boo = re.findall(r'var _blArr = \'(.*?)\';', aoo)[0]
    coo = json.loads(boo)
    for doo in coo:
        if doo['blname'] == "Summary of data filled in by students in the school":
            return doo['blpcurl']


def flowIdformId():
    headers = {
        'Cookie': cookies(jsond='cookies_njcit.json'),
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36'
    }
    url = blpcurl()
    aoo = requests.get(url=url, headers=headers).text
    flowId = re.findall(r'flowId = "(.*?)";', aoo)[0]
    formId = re.findall(r'formId = "(.*?)";', aoo)[0]
    return flowId, formId


def queryStatInfoForUnit():
    list = {}
    l = []
    a = 1
    aoo = flowIdformId()
    url = 'https://i.njcit.cn/EIP/cooperativestat/stat/queryStatInfoForUnit.htm'
    data = {
        'data': '{"flow_id":'
                f'"{aoo[0]}",'
                '"datetype":"thismonth","forms":[{"form_id":'
                f'"{aoo[1]}",'
                '"field":"","field_type":"","logicrelation":"","value":""}]}',
        'pageIndex': '0',
        'pageSize': '20'}
    headers = {'Cookie': cookies(jsond='cookies_njcit.json')}
    boo = requests.post(url=url, data=data, headers=headers).json()['data']
    for coo in boo:
        list[a] = [aoo[0], aoo[1], coo['unit_id'], coo['unit_name']]
        l.append([a, coo['unit_name']])
        a += 1
    l.append([a, 'All classes'])
    print(l)
    return list


# Get the list of unfilled persons in the class
def queryStatInfoForUser():
    list = []
    lists = []
    a = excel('Information Statistics.xlsx')
    headers = {'Cookie': cookies(jsond='cookies_njcit.json')}
    url = 'https://i.njcit.cn/EIP/cooperativestat/stat/queryStatInfoForUser.htm'
    aoo = queryStatInfoForUnit()
    moo = int(input('Please select a class:'))
    if moo == len(aoo) + 1:
        for v, boo in aoo.items():
            data = {
                'data': '{"flow_id":'
                        f'"{boo[0]}",'
                        '"unit_id":'
                        f'"{boo[2]}"'
                        ',"unit_name":'
                        f'"{boo[1]}"'
                        ',"datetype":"thismonth","forms":[{"form_id":'
                        f'"{boo[3]}"'
                        ',"field":"","field_type":"","logicrelation":"","value":""}]}',
                'pageIndex': '0',
                'pageSize': '100'}
            coo = requests.post(url=url, data=data, headers=headers).json()['data']
            for doo in coo:
                sj = doo['send_time'].split(' ')[0]
                daytime = time.strftime("%Y-%m-%d", time.localtime())
                if sj != daytime:
                    # print(boo[3], doo['user_name'], doo['send_time'])
                    list.append(doo['user_name'])
    else:
        boo = aoo[moo]
        data = {
            'data': '{"flow_id":'
                    f'"{boo[0]}",'
                    '"unit_id":'
                    f'"{boo[2]}"'
                    ',"unit_name":'
                    f'"{boo[1]}"'
                    ',"datetype":"thismonth","forms":[{"form_id":'
                    f'"{boo[3]}"'
                    ',"field":"","field_type":"","logicrelation":"","value":""}]}',
            'pageIndex': '0',
            'pageSize': '100'}
        coo = requests.post(url=url, data=data, headers=headers).json()['data']
        for doo in coo:
            sj = doo['send_time'].split(' ')[0]
            daytime = time.strftime("%Y-%m-%d", time.localtime())
            if sj != daytime:
                # print(boo[3], doo['user_name'], doo['send_time'])
                list.append(doo['user_name'])
    for booo in list:
        cooo = a.setdefault(booo)
        if not cooo is None:
            lists.append([booo, int(cooo[0]), int(cooo[1])])
        else:
            lists.append([booo, None, None])
    return lists

if __name__ == '__main__':

    # Writing is convenient for other teachers
    # use = input('Please enter account number: ')
    # psw = input('Please enter password: ')
    # login(username=use, password=psw)
    # print(aoo)

    # It is convenient for one teacher to use. If different teachers use it, please use the above method
    login(username='Change to your account', password='Change your password')
    aoo = queryStatInfoForUser()
    print(aoo)


    # # Punch in push 2.0
    # result = aoo
    # stu_dict = {}
    # for i in result:
    #     if i[2] in stu_dict.keys():
    #         stu_dict[i[2]].append([i[0], i[1]])
    #     else:
    #         stu_dict[i[2]] = [[i[0], i[1]]]
    #
    # url = 'https://qmsg.zendee.cn/group/f3edd116d32cb01e8567fbfb21a700f1'
    # now = datetime.datetime.now()
    # message = 'the list of students who have not clocked in today is as follows:' + '\ n'
    # for item in stu_dict:
    #     for student in stu_dict[item]:
    #         message = message + f'@at={student[1]}@({student[0]})\t'
    #     msg = {
    #         'msg': message + f'\n{now.hour} : {now.minute} : {now.second}',
    #         'qq': item
    #     }
    #
    #     if len(str(item)) != 0:
    #         requests.post(url, params=msg)
    #         print(str(item) + 'push succeeded')
    #         print(message)
    #     else:
    #         print(msg['msg '],' unable to push due to missing QQ group! ')
    #     sleep(60)
    #     message = 'the list of students who have not clocked in today is as follows:' + '\ n'



    # Push part
    # for boo in aoo:
    #     url = 'https://qmsg.zendee.cn/group/f3edd116d32cb01e8567fbfb21a700f1'
    #     msg = {
    #         'msg ':' @ at = '+ str (BOO [1]) +' @ '+' \ n '+ str (BOO [0]) +' classmate '+' \ n '+' please punch in as soon as possible!! ',
    #         'qq': str(boo[2])
    #     }
    #     requests.post(url, params=msg)
    #     print(str(boo[0]) + 'push succeeded')
    #     sleep(5)

 

 

Tags: Python html5

Posted on Wed, 01 Sep 2021 14:06:50 -0400 by Motionographer