Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Code cleanup, release 3.0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
qhy040404 committed Oct 8, 2022
1 parent 136f6db commit 6b86d7b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
28 changes: 12 additions & 16 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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:
Expand Down
31 changes: 16 additions & 15 deletions src/reserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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.'
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/version
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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])])
]
Expand Down

0 comments on commit 6b86d7b

Please sign in to comment.