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

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
qhy040404 committed Apr 7, 2022
1 parent 05bb92c commit 01067e0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/build.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pyinstaller -i logo.ico -F --version-file version main.py
pyinstaller -i logo.ico --version-file version main.py
pause
6 changes: 3 additions & 3 deletions src/main-non-Windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'},\
Expand Down Expand Up @@ -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')
Expand Down
15 changes: 10 additions & 5 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'},\
Expand All @@ -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:
Expand All @@ -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')
Expand Down
20 changes: 10 additions & 10 deletions src/reserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.')
Expand All @@ -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

0 comments on commit 01067e0

Please sign in to comment.