Use Python to achieve daily health check-in

Use Python to achieve daily health check-in

During the epidemic, the school required daily check-in in the health system. However, I kept forgetting to check-in, so I had an automatic check-in script to help me with the idea of ​​automatic check-in every day. So when I was fine, I studied the school's epidemic check-in system and wrote a small program for automatic check-in in Python.

1. Log in to the system

System login interface is very simple to do, there is no verification code and other authentication mechanism, use student number (the Account) , password (Password) can log into the system. I did a wrong login and used the packet capture tool to capture and analyze the packet. It was easy to find the login interface. It was observed that the login was to initiate a Post request to the login interface .
Login request
Continue to analyze and find that the information carried in the Post request is: user_account—student number , user_password—password , and the data is in json format.
Post request to carry data

Code
# 登录系统
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('{}登录成功'.format(account))
    else:
        print(res['msg'])
        print('{}登录失败'.format(account))

2. Get the non-check-in date

Recall the previous check-in process: After successfully entering the healthy check-in system, find the check-in date of the day and perform the check-in. The next thing to do is to get the check-in date. The analysis found that it was also a Post request, and the request did not carry any information.
Get the check-in date
After sending the Post request, the data returned is a json format. Analyzing the json data, it is found that the punch-in date is located in the datas—hunch_list . The number 0 is the date we need to punch the card, and date1 is the current punch-in date and state is the current date. Check in status, 0 means not clocked in, 1 means not clocked in. The program also judges the clock-in status. If the clock-in is not clocked in, the clock-in date is returned; if the clock is clocked in, the data is not returned.
Return data

Code
# 获取打卡日期
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('{},您{}已打卡'.format(res['datas']['user_info']['user_name'], res['datas']['hunch_list'][0]['date1']))
    else:
        print('{},您{}未打卡'.format(res['datas']['user_info']['user_name'], res['datas']['hunch_list'][0]['date1']))
        return res['datas']['hunch_list'][0]['date1']

3. Submit information

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

  1. mqszd: Current location? Shenyang City/Liaoning Province non-Shenyang City/other areas (non-Liaoning Province)

  2. sfybh: Fill in the previous day so far, is there any change in the current location (question 1)? no Yes

  3. mqstzk: Current physical condition? Good/Dry cough, fatigue, fever, dyspnea, etc./Medical observation and isolation/Suspected case/Confirmed case

  4. jcryqk: No contact with the following five categories of persons/confirmed cases/suspected persons/medical observers/persons entering and exiting medium-high-risk areas in the past 14 days

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

  6. jrcltw: Measure body temperature today (℃)

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

  8. jrlxfs: Please fill in family contact information

  9. xcsj: If the current location (question 1) has changed from the previous day, please fill in the departure time of the itinerary (example: 18:10), the means of transportation used and the train/flight number (example: train G8001), and the reason for going out (Example: Internship) (If you choose "Yes" for Question 2)

  10. gldd: For medical isolation observation or fixed-point isolation as required, please fill in the isolation start time and isolation location (for the case that "Protect yourself" is not selected in Question 6)

  11. zddw: My location (need to turn on the phone location function) 中国,**省,**市,**县<@>**

Put in our information and submit it in the Post request.
Information fill position

Fill in the example

{"mqszd":"其他地区(非辽宁省)","sfybh":"否","mqstzk":"良好","jcryqk":"未接触下述五类人员","glqk":"自行做好防护","jrcltw":"36.5","sjhm":"","jrlxfs":"","xcsj":"","gldd":"","zddw":"中国,**省,**市,**县(区)<@>**"}

Code
#提交表单
def punchForm(date):
    data = {
    
    
        'punch_form': '{"mqszd":"","sfybh":"","mqstzk":"","jcryqk":"","glqk":"","jrcltw":"","sjhm":"","jrlxfs":"","xcsj":"","gldd":"","zddw":"中国,**省,**市,**县(区)<@>**"}',
        '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('恭喜,打卡成功')
    else:
        print('糟糕,打卡失败')
        print('错误信息:\n{}'.format(res['msg'])

4. Overall analysis

Review the entire program, use request.session to maintain the login status, write the login login function, write the getHomeDate function to obtain the non-punch-in date, and write the punchForm punch-in information submission function. The most important thing is to analyze the web page request, and then write python code to simulate the punching behavior.

Guess you like

Origin blog.csdn.net/realxw/article/details/114002009