From 6b86d7b1a0f4374277424d5a3ea1744105c90858 Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Sat, 8 Oct 2022 15:52:01 +0800 Subject: [PATCH] Code cleanup, release 3.0.2.1 --- src/main.py | 28 ++++++++++++---------------- src/reserve.py | 31 ++++++++++++++++--------------- src/version | 8 ++++---- 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/src/main.py b/src/main.py index 303fcd2..27f7c92 100644 --- a/src/main.py +++ b/src/main.py @@ -11,7 +11,7 @@ import reserve # pre-define -ver = '3.0.1.9-pre2' +ver = '3.0.2.1' # initialize reserve.logging.info('Welcome to DLUT-library-auto-reservation ' + ver) @@ -53,9 +53,7 @@ while configData: reserve.logging.info('Splitting data') configData.pop(0) - data = configData.pop(0) - data = data.strip('\n') - data = data.split() + data = configData.pop(0).strip('\n').split() reserve.logging.info('Processing basic data.') user_id = data[0] @@ -74,14 +72,12 @@ # function email def send_email(seat=None, success=False, error=None): reserve.logging.info('Processing mail data.') - mailData = configData.pop(0) - mailData = mailData.strip('\n') - mailData = mailData.split() - - mail_user = mailData[0] - mail_pass = mailData[1] - sender = mailData[0] - receiver = mailData[0] + mail_data = configData.pop(0).strip('\n').split() + + mail_user = mail_data[0] + mail_pass = mail_data[1] + sender = mail_data[0] + receiver = mail_data[0] mail_temp_data = mail_user.split('@') mail_host_pre = 'smtp.' mail_host = mail_host_pre + mail_temp_data[1] @@ -102,10 +98,10 @@ def send_email(seat=None, success=False, error=None): message['To'] = receiver try: - smtpObj = smtplib.SMTP_SSL(mail_host, 465) - smtpObj.login(mail_user, mail_pass) - smtpObj.sendmail(sender, receiver, message.as_string()) - smtpObj.quit() + smtp_obj = smtplib.SMTP_SSL(mail_host, 465) + smtp_obj.login(mail_user, mail_pass) + smtp_obj.sendmail(sender, receiver, message.as_string()) + smtp_obj.quit() print('Email succeed') reserve.logging.info('Email succeed') except smtplib.SMTPException as e: diff --git a/src/reserve.py b/src/reserve.py index 1a8ab7b..465c981 100644 --- a/src/reserve.py +++ b/src/reserve.py @@ -76,15 +76,16 @@ def Reserve(user_id, password, wanted_seats, room_id): while True: # get seats status logging.info('Getting seats status') - room_available_map = s.get(room_available_map_url[0] + order_date + room_available_map_url[1] + room_id).text - room_available_map = room_available_map.strip('\ufeff\r\n\r\n[[{}]]\r\n\r\n\r\n\r\n') - room_available_map = room_available_map.split('},{') - room_available_map = (',').join(room_available_map) - room_available_map = room_available_map.split(',') + room_available_map = s\ + .get(room_available_map_url[0] + order_date + room_available_map_url[1] + room_id)\ + .text\ + .strip('\ufeff\r\n\r\n[[{}]]\r\n\r\n\r\n\r\n')\ + .split('},{') + room_available_map = ','.join(room_available_map).split(',') logging.debug('map: ' + str(room_available_map)) # check if available, get seat_id - isASeat = False + isSeat = False if type(wanted_seats) == str: logging.info('Data only includes 1 seat, mode 1') seat_label_num = wanted_seats @@ -95,7 +96,7 @@ def Reserve(user_id, password, wanted_seats, room_id): seat_type = int(room_available_map[j + 4].strip('"seat_type":"')) logging.info('Seat type data is ' + str(seat_type)) if seat_type == 1: - isASeat = True + isSeat = True logging.info('Seat valid and selected.') print('Seat selected.') break @@ -118,7 +119,7 @@ def Reserve(user_id, password, wanted_seats, room_id): logging.info('Seat type data is ' + str(seat_type)) if seat_type == 1: logging.info('Seat valid and selected') - isASeat = True + isSeat = True print('Seat selected.') break elif seat_type == 2 or seat_type == 3: @@ -130,10 +131,10 @@ def Reserve(user_id, password, wanted_seats, room_id): logging.warning('Seat invalid. Removing invalid data and switch to a valid seat.') print('Not a seat. Switching...') room_available_map.remove(seat_label) - if isASeat is True: + if isSeat is True: break - if isASeat is not True: + if isSeat is not True: logging.error('Seat unavailable or invalid. Check logs above.') print('Failed. Seat unavailable.') return None, nice, 'Type Error.' @@ -162,11 +163,11 @@ def Reserve(user_id, password, wanted_seats, room_id): # get addCode logging.info('Processing addCode') addCode = s.post(get_addCode_url, constructParaForAddCode(seat_id, order_date), - headers={'Content-Type': 'application/x-www-form-urlencoded'}).text - addCode = addCode.split(',') - addCode = addCode.pop() - addCode = addCode.lstrip('"addCode":"') - addCode = addCode.rstrip('"}}\r\n\r\n\r\n\r\n') + headers={'Content-Type': 'application/x-www-form-urlencoded'}).text\ + .split(',')\ + .pop()\ + .lstrip('"addCode":"')\ + .rstrip('"}}\r\n\r\n\r\n\r\n') logging.info('addCode is ' + addCode) # submit reserve post diff --git a/src/version b/src/version index 08e3420..7365136 100644 --- a/src/version +++ b/src/version @@ -6,8 +6,8 @@ VSVersionInfo( ffi=FixedFileInfo( # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4) # Set not needed items to zero 0. - filevers=(3, 0, 1, 9), - prodvers=(3, 0, 1, 9), + filevers=(3, 0, 2, 1), + prodvers=(3, 0, 2, 1), # Contains a bitmask that specifies the valid bits 'flags'r mask=0x3f, # Contains a bitmask that specifies the Boolean attributes of the file. @@ -31,10 +31,10 @@ VSVersionInfo( '080404b0', [StringStruct('CompanyName', 'qhy040404'), StringStruct('FileDescription', '大连理工大学图书馆自动预约座位小程序'), - StringStruct('FileVersion', '3.0.1.9'), + StringStruct('FileVersion', '3.0.2.1'), StringStruct(u'LegalCopyright', u'Copyright (C) 2022 qhy040404 All Rights Reserved'), StringStruct('ProductName', '大连理工大学图书馆自动预约座位小程序'), - StringStruct('ProductVersion', '3.0.1.9')]) + StringStruct('ProductVersion', '3.0.2.1')]) ]), VarFileInfo([VarStruct('Translation', [2052, 1200])]) ]