Skip to content

Commit

Permalink
Replace exit with raise Exception.
Browse files Browse the repository at this point in the history
用抛出异常来取代直接退出。
去除一些多余的代码。
  • Loading branch information
miaotony committed May 20, 2020
1 parent dc187c4 commit b87ea71
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 25 deletions.
8 changes: 3 additions & 5 deletions GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# -*- coding: utf-8 -*-
"""
GUI
bug:
stuID未能显示;没有对输入情况进行判断。
"""
import tkinter as tk
import tkinter.messagebox
Expand Down Expand Up @@ -200,8 +203,3 @@ def outputAs_all():
command=outputAs_all).place(x=30, y=300)

window.mainloop()

'''
bug:
stuID未能显示
'''
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Pull Requests & issues welcome!
@Author: MiaoTony, ZegWe, Cooook, Pinyi Qian
@UpdateLog: Please refer to `CHANGELOG.md`.
@ChangeLog: Please refer to `CHANGELOG.md`.
"""

Expand Down
5 changes: 2 additions & 3 deletions generateICS.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ def create_ics(lessons, semester_start_date):
try:
event.add('description', lesson.output_description(week=week))
except UnicodeDecodeError:
print("ERROR!")
exit(6) # 放弃python2.x了
raise Exception("ERROR!") # 放弃python2.x了
cal.add_component(event)
return cal

Expand Down Expand Up @@ -136,7 +135,7 @@ def export_ics(cal, semester_year, semester, stuID):
tem_path = os.path.abspath(tem.name)
tem.write(cal.to_ical())
tem_filename = tem.name
tem.read() # fix a py2.7 bug... issue#2
tem.read() # fix a py2.7 bug...
tem.close()
# print(getsizeof(tem.read()))
is_update = not is_same(tem_path, filename)
Expand Down
4 changes: 2 additions & 2 deletions generateXLSX.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def create_xls(lessons, semester_year, semester, stuID):
sheet.column_dimensions['A'].width = 3
sheet.row_dimensions[1].height = 20
sheet.row_dimensions[2].height = 20
# print('1\n')

for i in range(1, 12):
sheet.cell(i + 2, 1, i).alignment = alignment
sheet.row_dimensions[i + 2].height = 60
weekday = ['一', '二', '三', '四', '五', '六', '天']
ab = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']
# print('2\n')

for i in range(0, 7):
sheet.cell(2, i + 2, '星期' + weekday[i]).alignment = alignment
sheet.column_dimensions[ab[i + 1]].width = 20
Expand Down
21 changes: 10 additions & 11 deletions getClassSchedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,28 @@ def aao_login(stuID, stuPwd, captcha_str, retry_cnt=1):
logging.debug(r2.text)
temp_key = temp_token_match.search(r2.text)
if temp_key: # 找到密钥说明没有登录成功,需要重试
print("ID, Password or Captcha ERROR! Login ERROR!\n")
# print("ID, Password or Captcha ERROR! Login ERROR!\n")
temp_key = temp_key.group(1)
logging.debug(temp_key)
exit(2)
raise Exception("ID, Password or Captcha ERROR! Login ERROR!")
elif re.search(r"ui-state-error", r2.text): # 过快点击
print("ERROR! 请不要过快点击!\n")
time.sleep(1)
try_cnt += 1
# session.headers["User-Agent"] = UAs[1] # random.randint(0, len(UAs)-1) # 换UA也不行
# exit(3)
else:
temp_soup = BeautifulSoup(r2.text.encode('utf-8'), 'lxml')
name = temp_soup.find('a', class_='personal-name').string.strip()
print("Login OK!\nHello, {}!".format(name))
return name
else:
print("Login ERROR!\n")
exit(1)
# print("Login ERROR!\n")
raise Exception("Login ERROR!")
else:
print('Search token ERROR!\n')
exit(1)
print("ERROR! 过一会儿再试试吧...\n")
exit(3)
# print('Search token ERROR!\n')
raise Exception("Search token ERROR!")
# print("ERROR! 过一会儿再试试吧...\n")
raise Exception("ERROR! 过一会儿再试试吧...")


def getCourseTable(choice=0):
Expand Down Expand Up @@ -154,8 +153,8 @@ def getCourseTable(choice=0):
# logging.debug(session.cookies.get_dict())
return courseTable
else:
print("Get ids ERROR!")
exit(4)
# print("Get ids ERROR!")
raise Exception("Get ids ERROR!")


def parseCourseTable(courseTable):
Expand Down
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
# stuPwd = input('Please input your password:')
stuPwd = getpass('Please input your password:(不会回显,输入完成<ENTER>即可)')

# Captcha 验证码 # Fix Issue #13 bug, but only for Windows & MacOS.
# Captcha 验证码 # Fix Issue #13 bug.
captcha_resp = session.get(host + '/eams/captcha/image.action') # Captcha 验证码图片
img_path = os.path.join(os.getcwd(), 'captcha.jpg')
with open(img_path, 'wb') as captcha_fp:
Expand All @@ -95,6 +95,7 @@
os.startfile(img_path)
except:
from PIL import Image

# captcha_img = Image.open(BytesIO(captcha_resp.content))
captcha_img = Image.open(img_path)
captcha_img.show() # show the captcha
Expand Down Expand Up @@ -138,7 +139,7 @@
print("Thanks for your use! 欢迎来GitHub上点个Star呢!")

except Exception as e:
print("ERROR! 欢迎在GitHub上提出issue & Pull Request!")
print("ERROR! 如果遇到技术问题,欢迎在GitHub上提出issue & Pull Request!")
print(e)
finally:
session.cookies.clear() # 清一下cookie
Expand Down
2 changes: 1 addition & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

DEBUG = False

VERSION = "V0.15.1.20200520"
VERSION = "V0.15.2.20200520"

0 comments on commit b87ea71

Please sign in to comment.