The Birth of Library Self-service Reservation Software

demand analysis:

        In the last semester of my senior year, graduation is imminent, and I spent all day in the library preparing my graduation project. I met Pingping by chance, and then I realized that our school library can reserve seats for the next day at six o’clock one day in advance. There are no empty seats upstairs.

        It was still February, and the weather was still cold. There were many seats on the second and third floors, but most of them were in the lobby without air conditioning. Sitting there alone felt cold, and I couldn't even type the code. When I heard the news from her, I went back and set the alarm clock for 6 o'clock the next morning. Although I got a seat, it was really uncomfortable. After I woke up at 6 o'clock, I couldn't fall asleep. I went to the library at 1 o'clock. I didn't have enough energy, and finally couldn't take it anymore after two days in a row, so I decided to write a program to complete the automatic appointment function.


Start analysis:

        First of all, I have a general understanding of the entire process of the library, and found that it is not difficult, and it should be possible to do it.

The general steps are as follows:

  1. log in
  2. Obtain seat reservation information
  3. start booking

At first glance, it is quite simple, but as the functions become more and more perfect, it becomes more and more complicated.


Specific steps: 

  1. log in

        This kind of pure digital verification code, without adding interference lines, is just tilted. It is the simplest verification code. There is nothing to say, it is useless.

        f12 opens the browser developer tool, username and password are all native, and there is no doubt that verify is the verification code. Add headers and cookies first, and find that you can log in. OK, the first step is completed here.

        Paste the json data returned by successful login here, which will be used later. At first, I didn't notice this problem, which caused me to take a lot of detours. .

  

        2. Obtain seat information

         After I refreshed the page many times, I concluded that 17 is the number of each district on each floor. There are three districts on the second and third floors, and the numbers of each district are different. There is only one area for each floor above the fourth floor, and each floor has only a unique number. The latter id will be used when obtaining seat information. Speaking of this, I thought of a pit I stepped on. At the beginning, I only analyzed the data of one day. I thought that id (the segment used later) was fixed. , It’s just that the second day is one more than the first day, and I later learned that it is incremental. .

        When obtaining seat information, the two parameters of the previous request result were used. When I wrote this, I thought of another pitfall, which is startTime and endTime. If the seat is reserved on the day, startTime is the time when the request is initiated; if the seat is reserved for the next day, startTime is 08:00. And day is also the date of the next day, here I have another Baidu wheel, which can automatically get the date of the next day.

	def getTommrrow(self):
		inputdate = datetime.datetime.now().strftime('%Y-%m-%d')
		date = inputdate.split('-')
		inputyear = int(date[0])
		inputmonth = int(date[1])
		inputday = int(date[2])
		if inputmonth in [1, 3, 5, 7, 8, 10, 12]:
			enddate = 31
		elif inputmonth in [4, 6, 9, 11]:
			enddate = 30
		elif inputmonth % 4 == 0:
			enddate = 29
		else:
			enddate = 28
		if inputday < enddate:
			outputyear = inputyear
			outputmonth = inputmonth
			outputday = inputday + 1
		elif inputmonth == 12:
			outputyear = inputyear + 1
			outputmonth = 1
			outputday = 1
		else:
			outputyear = inputyear
			outputmonth = inputmonth + 1
			outputday = 1
		print(str(outputyear) + '-' + str(outputmonth).zfill(2) + '-' + str(outputday).zfill(2))
		self.tomorrow = str(outputyear) + '-' + str(outputmonth).zfill(2) + '-' + str(outputday).zfill(2)
		self.segment = int(self.tomorrow.replace('-', '')[-3:]) + self.primary_segment
		return

         The following is the response result of the seat reservation information

 

         The information needed here is id: represents the unique seat number, name and no are the same: represents the seat number, status: 1 represents free, 0 represents reserved. This is another pit I stepped on. Self-service reservation version 0.9 When the seat reservation you want to reserve is reserved, other seats will be automatically cycled. However, because the list index and seat number differ by one digit, my program will display that the reservation is successful, but the actual reserved seat is the wrong one. Number. There is also a bug. If the currently reserved seat is free and the next seat is reserved, the program will fall into an infinite loop and keep getting space reservation information. After analyzing the code, I found that I only return in the previous judgment, but the following judgment does not return, but continue!!!

        3. Finally, it’s time to make an appointment, so I’ll just post the code here

         You can see that the token and expire used in the reservation are the result of a successful login response.

        

 


 

Supplement and summary:

        The program uses ConfigParser to set configuration files, which is convenient for others to modify information and use.

        Use the scheduler to let the program run automatically at 6:00 every morning (bug: if the scheduler is set to 06:00, it will prompt that the appointment time has not arrived, generally set to 06:00:05)

        In version 0.9, only one seat number can be entered at a time. If the reservation is not available, you can only make a random reservation from the cycle.

        Version 1.0 changes the seat number to a form similar to a list, and you can set up alternate seats yourself.

        The combination of the program and the task plan management program is perfect. The task planner can make my program run automatically at 550,000 every morning, and automatically shut down after an hour, instead of keeping the program running at night. But it was successful yesterday morning. My computer shut down automatically this morning. I don’t know what happened. I’m going to try again tonight.

Guess you like

Origin blog.csdn.net/m0_54219225/article/details/123482664