Using Python to realize daily health punch in

Using Python to realize daily health punch in

During the epidemic, the school required to punch in the health system every day. However, I always forgot to punch in, so I had the idea of making an automatic punch in script to help me punch in every day. So when I was free, I studied the school's epidemic punch in system and wrote an automatic punch in applet in Python.

1. Log in to the system

The login interface of the system is still very simple, and there is no verification mechanism such as verification code. You can log in to the system by using account and password. Make a wrong login and use the packet capture tool to analyze the packet capture. It is easy to find the login interface. It is observed that the login is to send a Post request to the login interface.

After further analysis, it is found that the information carried by the Post request is: user_account - student number, user_password - password. The data is in json format.

code implementation
# Login system
def login(account, password):
    headers = {
        'User-Agent': 'Mozilla/5.0 (Linux; Android 10; V1914A Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045438 Mobile Safari/537.36 wxwork/3.1.1 MicroMessenger/7.0.1 NetType/WIFI Language/zh Lang/zh'
    }
    data = {
        'user_account': account,
        'user_password': password
    }
    login_url = parse.urljoin(url, 'login')
    res = session.post(login_url, headers=headers, data=json.dumps(data))
    res = res.json()
    status = res['code']
    if status == 200:
        print('{}Login successful'.format(account))
    else:
        print(res['msg'])
        print('{}Login failed'.format(account))

2. Get the date without clock in

Review the previous clock in process: after successfully entering the health clock in system, find the clock in date of the day and clock in. The next thing to do is to get the clock in date. The analysis shows that it is also a Post request, and the request does not carry any information.

After sending the Post request, the returned data is in json format. After analyzing the json data, it is found that the clock in date is located in data - hunch_ The punch out status in datelist is 1, the punch out date in datelist is 0, and the date we need to punch out is 0. The program also judges the clock out status. If it is not clocked out, the clock out date will be returned. If it is clocked out, no data will be returned.

code implementation
# Get clock in date
def getHomeDate():
    data = {

    }
    getHomeDate_url = parse.urljoin(url, 'getHomeDate')
    res = session.post(getHomeDate_url,data=json.dumps(data))
    res = res.json()
    if res['datas']['hunch_list'][0]['state'] == 1:
        print('{},you{}Clocked in'.format(res['datas']['user_info']['user_name'], res['datas']['hunch_list'][0]['date1']))
    else:
        print('{},you{}Not clocked in'.format(res['datas']['user_info']['user_name'], res['datas']['hunch_list'][0]['date1']))
        return res['datas']['hunch_list'][0]['date1']

3. Submission of information

The next step is to submit information. Just write the Data contained in the request header submitted by clocking in. The information contained in the request header is as follows:

  1. mqszd: current location? Shenyang City / Liaoning Province non Shenyang City / other regions (non Liaoning Province)

  2. sfybh: is there any change in the current location (question 1) so far? No / Yes

  3. mqstzk: what is your current physical condition? Good / dry cough, fatigue, fever, dyspnea and other diseases / medical observation isolation / suspected cases / confirmed cases

  4. jcryqk: no contact with the following five categories of personnel in recent 14 days / confirmed cases / suspected personnel / medical observers / people in and out of medium and high-risk areas

  5. glqk: self protection / medical isolation observation / fixed-point isolation as required

  6. jrcltw: measure your temperature today (℃)

  7. sjhm: Please fill in your current personal mobile phone number

  8. jrlxfs: Please fill in the contact information of your family

  9. xcsj: if the current location (question 1) has changed compared with the data filled in the previous day, please fill in the departure time of the trip (e.g. 18:10), the vehicle and train number / flight number used (e.g. train G8001), and the reason for going out (e.g. Internship) (select "yes" for question 2)

  10. gldd: for medical isolation observation or fixed-point isolation as required, please fill in the starting time and place of isolation (for the case where "self protection" is not selected in question 6)

  11. zddw: my location (you need to turn on the mobile location function) China, * * Province, * * City, * * County < @ >**

Put in our information and submit it in the Post request.

Fill in examples

{"mqszd": "other regions (not Liaoning Province)", "sfybh": "no", "mqstzk": "good", "jcryqk": "not contacting the following five categories of personnel", "glqk": "protect yourself", "jrcltw":"36.5","sjhm":"","jrlxfs":"","xcsj":"","gldd":"","zddw": "China, * * Province, * * City, * * county (District) < @ > * *"}

code implementation
#Submit Form 
def punchForm(date):
    data = {
        'punch_form': '{"mqszd":"","sfybh":"","mqstzk":"","jcryqk":"","glqk":"","jrcltw":"","sjhm":"","jrlxfs":"","xcsj":"","gldd":"","zddw":"China,**province,**city,**county(area)<@>**"}',
        'date': date
    }
    punchForm_url = parse.urljoin(url, 'punchForm')
    res = session.post(punchForm_url, data=json.dumps(data))
    res = res.json()
    if res['code'] == 200:
        print('Congratulations, punch in')
        print('Clock in temperature today:{}'.format(temperature))
    else:
        print('No, the clock failed')
        print('Error message:\n{}'.format(res['msg'])

4. Overall analysis

Review the whole procedure and use request The session keeps the login status, the login function is written, the getHomeDate function is written, and the punchForm punch in information submission function is written. The most important thing is to analyze the web page request, and then write python code to simulate the clock in behavior.

Tags: Python crawler

Posted by khr2003 on Sat, 16 Apr 2022 10:28:22 +0930