当前位置:网站首页>Library automatic reservation script

Library automatic reservation script

2022-07-28 12:37:00 wechannn

Preface

This summer vacation , Having not chosen to stay in school, I resolutely chose to go home . Thinking of going home and lying flat , Occasionally, I can often go City Library volume .
However , Because of the requirements of epidemic prevention and control, you need to make an appointment one day in advance to enter the Library . Of course, we must actively cooperate and abide by the regulations .
however , The reserved opening hours of the library are every morning 6 O 'clock , As the wave of the Internet, of course ... Don't get up so early .
So when I got up and opened the system to make an appointment, I found
 Insert picture description here

As a Diligent and studious Of Excellent college students , Of course, you can't be defeated by this little difficulty , So there is As the title . Get on the train !!!

Grab the bag

 Insert picture description here
The reservation system of the municipal library is established in WeChat official account Upper .

Here is the first pit , This system can only be accessed on wechat clients , But not in edge、Firefox、Chrome Wait for the browser to access directly .

One solution is to access the wechat developer tool to capture packets , But I am Ubuntu The system of , Wechat developer tools haven't been released yet Linux edition ( Bad review ), We have to stop .

The second scheme is adopted here , Grab bags on your mobile phone ,iOS and Android Search all major packet capturing tools by yourself . Grab post and get Requested json Format data packets for parsing .

analysis

According to the analysis of packet capturing results ,subLibId and scheduleId Of title They are the number of the library and the number of the reservation period .

Other information is some equipment account verification information and personal appointment registration information .

simulation

After bag grabbing , Use python Write a code script to simulate the mobile wechat client sending a request to the node of the target server .

I don't say much nonsense , Go straight to the code , For personal information ##### Instead of

import requests
import time
import datetime
import json

#  First create url  and  headers, And then directly request See if it works .
url = 'https://appointment-backend-cdn.dataesb.com/api/appointment/pub_add/'

header = {
    
    "Accept": "application/json, text/plain, */*",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "zh-CN",
    "User-Agent": "#####",
    "Referer": "https://appointment-users.dataesb.com/",
    "unionid": "#####",
    "Content-Length": "173",
    "Content-Type": "application/json;charset=UTF-8",
    "Origin": "https://appointment-users.dataesb.com",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "same-site",
    "Connection": "keep-alive",
    "Host": "appointment-backend-cdn.dataesb.com"
}
Id = #####
scheduleId_t = #####

def re_exe(inc=20):
    global scheduleId_t
    while True:
        time.sleep(inc)
        if datetime.datetime.now().hour == 6:
            scheduleId_t += 1
        if datetime.datetime.now().hour == 5:
            scheduleId_t = #####

        post_data = {
    
            "subLibId": Id,
            "scheduleId": scheduleId_t,
            "children": 0,
            "card": "#####",
            "cardType": "IDCARD",
            "name": "#####",
            "phone": "#####",
            "childrenConfig": True,
            "code": ""
        }
        time_str_13 = int(float(time.time()) * 1000)  #  Create timestamps 
        param = {
    
            "timestamp": time_str_13,
            "callback": "#####"
        }
        #  Then execute it like this 
        if datetime.datetime.now().hour == 6:
            r1 = requests.post(url, json=post_data, headers=header, params=param, verify=False)
            print(scheduleId_t)
            print(r1.json())


re_exe(20)

Try to run , And print out the result of the appointment . return 200, And you can see the printed appointment results in the log , Perfect solution .

END

The script code is done , It's impossible to keep 24 Leave the computer running for hours . So we need a server to do it , It happens that my one hasn't expired yet . Timing task ,emmm Not so much ...

So let the program run in the server all the time , The logic of program execution is continuous loop execution , At the same time, the time function is used . The above code sets 6'o clock Automatically make an appointment for me every time I arrive 20 second Ask for once , Prevent him from exploding his database too often and being found by him ...

Be careful , because scheduleId_t It may be changed due to the setting of the background of the library staff , No parsing is sent here get Request to update the running scheduleId_t, Instead, the request is sent by setting the initialization value to increment . Therefore, the initial value needs to be checked irregularly to see whether it needs to be changed .

Use scp command , Transfer the script file to the remote server .

scp  Script path   Server path 

The last pit !!! Terminal exit ssh After connecting to the server remotely , The program executed will also terminate . So you need to run the program persistently on the terminal . Use the following command to make the program run automatically in the background , After the remote connection is closed, it also continues to run .

nohup python3 -u *****.py > log.out 2>&1 &

nohup and **& Double insurance , At the same time, the information printed by the program is saved here journal ** in .

Use the following command to check whether there is a process executor .

ps aux

Call it a day , Next, enjoy the air conditioning of the library during the summer vacation .

原网站

版权声明
本文为[wechannn]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207281133058486.html