diff --git a/src/build.bat b/src/build.bat index 3dcf4d7..a9e3db9 100644 --- a/src/build.bat +++ b/src/build.bat @@ -1,2 +1,2 @@ -pyinstaller -i logo.ico -F --version-file version main.py +pyinstaller -i logo.ico --version-file version main.py pause \ No newline at end of file diff --git a/src/main-non-Windows.py b/src/main-non-Windows.py index 6c02396..d6f4715 100644 --- a/src/main-non-Windows.py +++ b/src/main-non-Windows.py @@ -6,7 +6,7 @@ from email.mime.text import MIMEText # initialize map -area_map = {'伯川': '17', '令希': '32'} +area_map = {'BC': '17', 'LX': '32'} room_map = {'17': {'301': '168', '312': '170', '401': '195',\ '404': '197', '409': '196', '501': '198',\ '504': '199', '507': '200'},\ @@ -39,9 +39,9 @@ seatData = configData.pop(0) seatData = seatData.strip('\n') - wanted_seats = seatData.split("-") + wanted_seats = seatData.split() - # 邮件功能 + # function email def send_email(seat = None, success = False, error = None): mailData = configData.pop(0) mailData = mailData.strip('\n') diff --git a/src/main.py b/src/main.py index 3c98b7a..506f293 100644 --- a/src/main.py +++ b/src/main.py @@ -7,7 +7,7 @@ import os # initialize map -area_map = {'伯川': '17', '令希': '32'} +area_map = {'BC': '17', 'LX': '32'} room_map = {'17': {'301': '168', '312': '170', '401': '195',\ '404': '197', '409': '196', '501': '198',\ '504': '199', '507': '200'},\ @@ -18,7 +18,7 @@ # Read config -with open("config.conf","r",encoding='gb18030') as config: +with open("config.conf","r") as config: configData = config.readlines() configData.pop(0) if len(configData) == 1: @@ -31,19 +31,24 @@ data = configData.pop(0) data = data.strip('\n') data = data.split() + print(data) user_id = data[0] password = data[1] area_name = data[2] room_name = data[3] area_id = area_map.get(area_name) - room_id = room_map.get(area_id).get(room_name) + print(area_id) + temp_map = room_map.get(area_id) + print(temp_map) + room_id = temp_map.get(room_name) + print(room_id) seatData = configData.pop(0) seatData = seatData.strip('\n') - wanted_seats = seatData.split("-") + wanted_seats = seatData.split() - # 邮件功能 + # function email def send_email(seat = None, success = False, error = None): mailData = configData.pop(0) mailData = mailData.strip('\n') diff --git a/src/reserve.py b/src/reserve.py index 14c1c2a..9083127 100644 --- a/src/reserve.py +++ b/src/reserve.py @@ -32,28 +32,28 @@ def constructParaForAddSeat(addCode): return '&'.join([i+'='+j for i, j in al.items()]) def Reserve(user_id, password, wanted_seats, room_id): - # 执行状态定义 + # define result nice = False - # 登录并检查登录状态 + # login and check session online = False while online is not True: s = sso.login(id=user_id, passwd=password) ifLogin = s.get(session_stat).text - if '用户在线' in ifLogin: + if 'user_id' in ifLogin: online = True else: print('Login error.') del s - # 获取座位状态 + # get 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(',') - # 查看座位是否可用,获取seat_id + # check if available, get seat_id isASeat = False if type(wanted_seats) == str: seat_label_num = wanted_seats @@ -100,23 +100,23 @@ def Reserve(user_id, password, wanted_seats, room_id): return None, nice, 'Status Error.' seat_id = room_available_map[j - 1].strip('"seat_id":""') - # 检查是否仍然在线 + # check session again checkSession = s.get(session_stat).text - if '用户在线' in checkSession: + if 'user_id' in checkSession: pass else: print('Logged out. Sending login request.') del s s = sso.login(id=user_id, passwd=password) - # 提取addCode + # get 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') - # 提交预约post + # submit reserve post reserve_response = s.post(addSeat_url, constructParaForAddSeat(addCode), headers={'Content-Type': 'application/x-www-form-urlencoded'}).text if '预约成功' in reserve_response: print('Success.') @@ -126,6 +126,6 @@ def Reserve(user_id, password, wanted_seats, room_id): print('Last Step Error.') error = reserve_response - # 登出 + # logout s.get(logout_url) return seat_label_num, nice, error \ No newline at end of file