Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #35 from jameshwc/dev
Browse files Browse the repository at this point in the history
v2.1.0
  • Loading branch information
jameshwc authored May 6, 2022
2 parents 52cb959 + 0ae22d3 commit 6354335
Show file tree
Hide file tree
Showing 18 changed files with 278 additions and 161 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ jobs:
- name: Add version
run: |
perl -i -pe's/VERSION/V${{ env.VERSION }}/g' gui_main.py
perl -i -pe's/self.version: str = \"1.0\"/self.version = \"${{ env.VERSION }}\"/g' ceiba/ceiba.py
- name: test
run: cat ceiba/ceiba.py
perl -i -pe's/VERSION/V${{ env.VERSION }}/g' src/gui_main.py
perl -i -pe's/self.version: str = \"1.0\"/self.version = \"${{ env.VERSION }}\"/g' src/ceiba/ceiba.py
- name: Set up python version
uses: actions/setup-python@v2
Expand All @@ -58,6 +55,10 @@ jobs:
- name: Install PyInstaller
run: pip3 install pyinstaller

- name: Install PIL MacOS missing
run: pip3 install Pillow
if: ${{ matrix.os == 'macos-latest' }}

- name: Package Application
run: pyinstaller ceiba-downloader.spec

Expand Down
13 changes: 6 additions & 7 deletions ceiba-downloader.spec
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
block_cipher = None


a = Analysis(['gui_main.py'],
a = Analysis(['src/gui_main.py'],
pathex=[],
binaries=[],
datas=[('resources/custom.qss', 'resources'),
('resources/GenSenRounded-M.ttc', 'resources'),
('resources/ceiba.ico', 'resources'),
('ceiba/i18n/*', 'resources/i18n')],
datas=[('src/resources/custom.qss', 'resources'),
('src/resources/GenSenRounded-M.ttc', 'resources'),
('src/resources/ceiba.ico', 'resources')],
hiddenimports=[],
hookspath=[],
hooksconfig={},
Expand All @@ -37,7 +36,7 @@ exe = EXE(pyz,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon='resources/ceiba.ico')
icon='src/resources/ceiba.ico')
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
Expand All @@ -48,5 +47,5 @@ coll = COLLECT(exe,
name='ceiba-downloader')
app = BUNDLE(coll,
name='ceiba-downloader.app',
icon='resources/ceiba.ico',
icon='src/resources/ceiba.ico',
bundle_identifier=None)
File renamed without changes.
154 changes: 126 additions & 28 deletions ceiba/const.py → src/ceiba/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from enum import Enum
import json
from pathlib import Path
from typing import Dict
from .i18n.en import en
from .i18n.zh_tw import zh_tw

cname_map = {
'bulletin': '公佈欄', 'syllabus': '課程大綱', 'hw': '作業',
'info': '課程資訊', 'personal': '教師資訊', 'grade': '學習成績',
'board': '討論看板', 'calendar': '課程行事曆', 'share': '資源分享',
'vote': '投票區', 'student': '修課學生'}
ename_map = {v: k for k, v in cname_map.items()}

class Role(Enum):
Student = 0
Expand All @@ -25,40 +32,21 @@ def __init__(self):

self._data: Dict[str, Dict[str, str]] = {}

# self._qt_feedback = {}
# self._qt_submit = {}
# self._qt_anonymous = {}
# self._qt_submit_ticket_successfully = {}
# self._qt_user = {}
# self._qt_username = {}
# self._qt_password = {}
# self._qt_login = {}
# self._qt_login_method_unsafe = {}
# self._qt_login_method_safe = {}
# self._qt_course = {}
# self._qt_status = {}
# self._qt_send_ticket_button = {}

self.load_json('zh-tw')
self.load_json('en')

def load_json(self, lang):
try:
with open(list(Path().glob(f'**/i18n/{lang}.json'))[0], 'r', encoding='utf-8') as fp:
data = json.load(fp)
except (FileNotFoundError, IndexError):
raise
self.load_dict('zh-tw', zh_tw)
self.load_dict('en', en)

def load_dict(self, lang, lang_dict):

for role in Role:
name = role.name
self.init_str(f'role_{role}')
self._data[f'role_{role}'][lang] = data['role'][name]
self._data[f'role_{role}'][lang] = lang_dict['role'][name]

for info, str_ in data['info'].items():
for info, str_ in lang_dict['info'].items():
self.init_str(info)
self._data[info][lang] = str_

for qt, str_ in data['qt'].items():
for qt, str_ in lang_dict['qt'].items():
self.init_str(f'qt_{qt}')
self._data[f'qt_{qt}'][lang] = str_

Expand All @@ -79,6 +67,12 @@ def course(self, course_name: str, course_num: str, class_num: str) -> str:
return self._data['course'][self.lang].format(course_name, course_num, class_num)
return self._data['course_without_class'][self.lang].format(course_name, course_num)

@property
def name_map(self) -> Dict[str, str]:
if self.lang == 'zh-tw':
return cname_map
return ename_map

@property
def sso_login(self) -> str:
return self._data['sso_login'][self.lang]
Expand Down Expand Up @@ -275,6 +269,10 @@ def try_to_stop_download(self) -> str:
def stop_download(self) -> str:
return self._data['stop_download'][self.lang]

@property
def qt_stop_button(self) -> str:
return self._data['qt_stop_button'][self.lang]

@property
def qt_pause_button(self) -> str:
return self._data['qt_pause_button'][self.lang]
Expand All @@ -287,4 +285,104 @@ def qt_resume_button(self) -> str:
def qt_login_method_label(self) -> str:
return self._data['qt_login_method_label'][self.lang]

@property
def qt_login_groupbox_title(self) -> str:
return self._data['qt_login_groupbox_title'][self.lang]

@property
def qt_username_label(self) -> str:
return self._data['qt_username_label'][self.lang]

@property
def qt_password_label(self) -> str:
return self._data['qt_password_label'][self.lang]

@property
def qt_login_button(self) -> str:
return self._data['qt_login_button'][self.lang]

@property
def qt_login_method_left_label(self) -> str:
return self._data['qt_login_method_left_label'][self.lang]

@property
def qt_login_method_right_label(self) -> str:
return self._data['qt_login_method_right_label'][self.lang]

@property
def qt_login_method_left_label_tooltip(self) -> str:
return self._data['qt_login_method_left_label_tooltip'][self.lang]

@property
def qt_login_method_right_label_tooltip(self) -> str:
return self._data['qt_login_method_right_label_tooltip'][self.lang]

@property
def qt_welcome(self) -> str:
return self._data['qt_welcome'][self.lang]

@property
def qt_courses_group_box(self) -> str:
return self._data['qt_courses_group_box'][self.lang]

@property
def qt_status_group_box(self) -> str:
return self._data['qt_status_group_box'][self.lang]

@property
def qt_download_button(self) -> str:
return self._data['qt_download_button'][self.lang]

@property
def qt_check_all_courses_checkbox(self) -> str:
return self._data['qt_check_all_courses_checkbox'][self.lang]

@property
def qt_download_item_label(self) -> str:
return self._data['qt_download_item_label'][self.lang]

@property
def qt_check_all_download_item_checkbox(self) -> str:
return self._data['qt_check_all_download_item_checkbox'][self.lang]

@property
def qt_download_admin_checkbox(self) -> str:
return self._data['qt_download_admin_checkbox'][self.lang]

@property
def qt_download_admin_checkbox_tooltip(self) -> str:
return self._data['qt_download_admin_checkbox_tooltip'][self.lang]

@property
def qt_only_download_homepage_checkbox(self) -> str:
return self._data['qt_only_download_homepage_checkbox'][self.lang]

@property
def qt_only_download_homepage_checkbox_tooltip(self) -> str:
return self._data['qt_only_download_homepage_checkbox_tooltip'][self.lang]

@property
def qt_filepath_label(self) -> str:
return self._data['qt_filepath_label'][self.lang]

@property
def qt_file_browse_button(self) -> str:
return self._data['qt_file_browse_button'][self.lang]

@property
def qt_download_item_menu_button(self) -> str:
return self._data['qt_download_item_menu_button'][self.lang]

@property
def qt_download_finish_msgbox(self) -> str:
return self._data['qt_download_finish_msgbox'][self.lang]

@property
def qt_download_finish_msgbox_open_dir(self) -> str:
return self._data['qt_download_finish_msgbox_open_dir'][self.lang]

@property
def qt_download_finish_msgbox_open_browser(self) -> str:
return self._data['qt_download_finish_msgbox_open_browser'][self.lang]

strings = String()
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 32 additions & 6 deletions ceiba/i18n/en.json → src/ceiba/i18n/en.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
en = {
"role": {
"Student": "NTU Students",
"TA": "TA",
Expand Down Expand Up @@ -27,8 +27,8 @@
"error_skip_and_continue_download_modules": "Error when downloading {1} of {0}! Skip it and continue downloading...",
"error_skip_and_continue_download_courses": "Error when downloading the course {}! Skip it and continue downloading...",
"error_unable_to_parse_course_sn": "Can't parse the course code of {} ! Cancel the download of {}...",
"try_to_login": "Trying to log in Ceiba...",
"login_successfully": "Successfully log in to Ceiba!",
"try_to_login": "Trying to sign in Ceiba...",
"login_successfully": "Successfully sign in to Ceiba!",
"try_to_get_courses": "Trying to get the courses...",
"get_courses_successfully": "Successfully got the courses!",
"start_downloading_courses": "Downloading the courses...",
Expand All @@ -41,8 +41,8 @@
"urlf": "url: {}",
"url_duplicate": "duplicate url: skipping download - {}",
"exception_invalid_login_parameters": "You must fill in the username/password or cookies!",
"exception_invalid_login_role": "Fail to log in! Please provide a login role (NTU Students, Professor, etc.)!",
"exception_invalid_credentials": "Fail to log in! Please check if you fill in correct username and password!",
"exception_invalid_login_role": "Fail to sign in! Please provide a login role (NTU Students, Professor, etc.)!",
"exception_invalid_credentials": "Fail to sign in! Please check if you filled in correct username and password!",
"exception_invalid_filepath": "The file path is incorrect! Please check if the path is empty or wrong!",
"exception_null_ticket_content": "The content is empty! You must type something to submit issues!",
"exception_send_ticket_error": "Fail to report issue! Error: {}",
Expand All @@ -62,8 +62,34 @@
},

"qt": {
"login_groupbox_title": "User",
"username_label": "Username (Student ID): ",
"password_label": "Password: ",
"login_button": "Sign in",
"login_method_left_label": "Username/Password [?]",
"login_method_right_label": "Cookies [?]",
"login_method_left_label_tooltip": "It's unsafe to sign in via a third-party program! You should use cookies as your credential instead.",
"login_method_right_label_tooltip": "Sign in Ceiba manually and you can view cookies using F12 in your browser. Please copy the content of PHPSESSID in your cookies.",
"welcome": "Welcome, {} ({})!",
"courses_group_box": "Courses",
"status_group_box": "Status",
"download_button": "Download",
"check_all_courses_checkbox": "Check All Courses",
"download_item_label": "Download Items: ",
"check_all_download_item_checkbox": "Check All Items ",
"download_admin_checkbox": "Download Admin Pages [?]",
"download_admin_checkbox_tooltip": "Download Ceiba Admin Pages (only available for TAs, Professors, and Outside Teachers.",
"only_download_homepage_checkbox": "Only Homepage [?]",
"only_download_homepage_checkbox_tooltip": "Download Ceiba homepage only.\\nYou should use this option when you had downloaded a few courses before\\n and don't want to repetively download those courses.",
"filepath_label": "Path: ",
"file_browse_button": "Browse",
"download_item_menu_button": "<-- Click to expand -->",
"stop_button": "Stop Download",
"pause_button": "Pause Download",
"resume_button": "Resume Download",
"login_method_label": "Login Method:"
"login_method_label": "Login Method:",
"download_finish_msgbox": "The download has completed!",
"download_finish_msgbox_open_dir": "Open Ceiba directory",
"download_finish_msgbox_open_browser": "Open Ceiba homepage"
}
}
30 changes: 28 additions & 2 deletions ceiba/i18n/zh-tw.json → src/ceiba/i18n/zh_tw.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
zh_tw = {
"role": {
"Student": "台大學生",
"TA": "助教",
Expand Down Expand Up @@ -62,8 +62,34 @@
},

"qt": {
"login_groupbox_title": "使用者",
"username_label": "帳號 (學號) :",
"password_label": "密碼 :",
"login_button": "登入",
"login_method_left_label": "認證方式:帳號 / 密碼 [?]",
"login_method_right_label": "cookies [?]",
"login_method_left_label_tooltip": "除非你信任本程式作者,否則不應該在計中網站以外的地方輸入自己的帳密!",
"login_method_right_label_tooltip": "透過手動登入 Ceiba 可以從瀏覽器的 F12 視窗看到 Cookies,請複製 PHPSESSID 的內容",
"welcome": "{} ({}),歡迎你!",
"courses_group_box": "課程",
"status_group_box": "狀態",
"download_button": "下載",
"check_all_courses_checkbox": "勾選所有課程",
"download_item_label": " 下載項目: ",
"check_all_download_item_checkbox": " 勾選全部下載項目 ",
"download_admin_checkbox": "下載管理後台 [?]",
"download_admin_checkbox_tooltip": "下載 Ceiba 管理後臺(只有助教、教授與校外老師適用)",
"only_download_homepage_checkbox": " 只下載首頁[?] ",
"only_download_homepage_checkbox_tooltip": "只下載 Ceiba 首頁。當你已經下載了部分課程,且不希望重複下載那些課程時,可以勾選這個選項。",
"filepath_label": " 存放路徑: ",
"file_browse_button": "瀏覽",
"download_item_menu_button": "<-- 點我展開 -->",
"stop_button": "停止下載",
"pause_button": "暫停下載",
"resume_button": "繼續下載",
"login_method_label": "登入方式:"
"login_method_label": "登入方式:",
"download_finish_msgbox": "下載完成!",
"download_finish_msgbox_open_dir": "打開檔案目錄",
"download_finish_msgbox_open_browser": "打開 Ceiba 網頁"
}
}
File renamed without changes.
14 changes: 5 additions & 9 deletions ceiba/util.py → src/ceiba/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from operator import truediv
import re
import time

import os
from requests import Session, Response
from typing import Callable
from .const import strings, Role
from .exceptions import CrawlerConnectionError, StopDownload
from pathlib import Path
from os.path import relpath

from .const import strings, Role, cname_map
from .exceptions import CrawlerConnectionError, StopDownload

CONNECT_RETRY_MAX = 10
REQUESTS_TIMEOUT = 300
PAUSE = False
Expand All @@ -36,12 +37,7 @@
admin_url = 'https://ceiba.ntu.edu.tw/course_admin/?csno='
skip_courses_list = ['中文系大學國文網站']

cname_map = {
'bulletin': '公佈欄', 'syllabus': '課程大綱', 'hw': '作業',
'info': '課程資訊', 'personal': '教師資訊', 'grade': '學習成績',
'board': '討論看板', 'calendar': '課程行事曆', 'share': '資源分享',
'vote': '投票區', 'student': '修課學生'}
ename_map = {v: k for k, v in cname_map.items()}


admin_cname_map = {
'ftp': '檔案上傳', 'user': '使用者', 'theme': '主題首頁',
Expand Down
Loading

0 comments on commit 6354335

Please sign in to comment.