Skip to content

Commit

Permalink
Merge branch 'master' into update_ischool_login_method_with_retry
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Lu-none authored Feb 28, 2024
2 parents bf23aa0 + 97a78a3 commit 23ff926
Show file tree
Hide file tree
Showing 17 changed files with 607 additions and 10 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ android {

defaultConfig {
applicationId "club.ntut.npc.tat"
minSdkVersion 23
minSdkVersion 24
targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
9 changes: 9 additions & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class MessageLookup extends MessageLookupByLibrary {
"accountLock": MessageLookupByLibrary.simpleMessage("Account is locked, please try again in 15 minutes"),
"accountNull": MessageLookupByLibrary.simpleMessage("Please enter your account"),
"accountPasswordError": MessageLookupByLibrary.simpleMessage("Account password incorrect"),
"aduit": MessageLookupByLibrary.simpleMessage("Aduit"),
"aestheticDimension": MessageLookupByLibrary.simpleMessage("Aesthetic dimension"),
"alertError": MessageLookupByLibrary.simpleMessage("An error occurred"),
"androidPrivateBrowseGuideSubTitle":
Expand Down Expand Up @@ -122,6 +123,8 @@ class MessageLookup extends MessageLookupByLibrary {
"getCalendar": MessageLookupByLibrary.simpleMessage("Getting calendar..."),
"getCalendarError": MessageLookupByLibrary.simpleMessage("Getting calendar error"),
"getCourse": MessageLookupByLibrary.simpleMessage("Get schedule..."),
"getCourseClassmateList": MessageLookupByLibrary.simpleMessage("Getting classmate list..."),
"getCourseClassmateListError": MessageLookupByLibrary.simpleMessage("Get classmate list error"),
"getCourseDetail": MessageLookupByLibrary.simpleMessage("Reading course materials..."),
"getCourseDetailError": MessageLookupByLibrary.simpleMessage("Course data reading error"),
"getCourseError": MessageLookupByLibrary.simpleMessage("Getting schedule error"),
Expand Down Expand Up @@ -181,6 +184,8 @@ class MessageLookup extends MessageLookupByLibrary {
"logoutWarning":
MessageLookupByLibrary.simpleMessage("Are you sure you want to log out? \nAll data will be cleared"),
"missingRequiredInformation": MessageLookupByLibrary.simpleMessage("Missing required information"),
"name": MessageLookupByLibrary.simpleMessage("name"),
"nationalTaipeiUniversity": MessageLookupByLibrary.simpleMessage("NTPU"),
"naturalDimension": MessageLookupByLibrary.simpleMessage("Natural dimension"),
"needsVerifyMobileWarning": MessageLookupByLibrary.simpleMessage(
"You may be asked to verify your phone number\nplease check the website entrance for further information."),
Expand Down Expand Up @@ -270,10 +275,12 @@ class MessageLookup extends MessageLookupByLibrary {
"sociologicalDimension": MessageLookupByLibrary.simpleMessage("Sociological Dimension"),
"sortBy": MessageLookupByLibrary.simpleMessage("Sort by"),
"startClass": MessageLookupByLibrary.simpleMessage("Start class"),
"studentId": MessageLookupByLibrary.simpleMessage("student id"),
"studentList": MessageLookupByLibrary.simpleMessage("Student list"),
"subscribe": MessageLookupByLibrary.simpleMessage("Subscribe"),
"sure": MessageLookupByLibrary.simpleMessage("Sure"),
"syllabus": MessageLookupByLibrary.simpleMessage("Syllabus"),
"taipeiMedicineUniversity": MessageLookupByLibrary.simpleMessage("TMU"),
"takeCore": MessageLookupByLibrary.simpleMessage("Take core"),
"takeForeignDepartmentCredits": MessageLookupByLibrary.simpleMessage("Foreign Dep Credits"),
"takeForeignDepartmentCreditsLimit": MessageLookupByLibrary.simpleMessage("Credit limit"),
Expand All @@ -285,9 +292,11 @@ class MessageLookup extends MessageLookupByLibrary {
"titleScore": MessageLookupByLibrary.simpleMessage("Score"),
"totalAverage": MessageLookupByLibrary.simpleMessage("Total average"),
"totalPeople": MessageLookupByLibrary.simpleMessage("Total people"),
"unknownDepartment": MessageLookupByLibrary.simpleMessage("Unknown Department"),
"unknownError": MessageLookupByLibrary.simpleMessage("An unknown error occurred"),
"unknownServerError": MessageLookupByLibrary.simpleMessage(
"A problem occurred when communicating with the campus server, most features may be affected\nPlease confirm that the campus system can be used normally and try again, thanks"),
"unknownStudent": MessageLookupByLibrary.simpleMessage("Unknown Student"),
"update": MessageLookupByLibrary.simpleMessage("Update"),
"useOldPassword": MessageLookupByLibrary.simpleMessage("Use old password"),
"versionInfo": MessageLookupByLibrary.simpleMessage("Version info"),
Expand Down
9 changes: 9 additions & 0 deletions lib/generated/intl/messages_zh_TW.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MessageLookup extends MessageLookupByLibrary {
"accountLock": MessageLookupByLibrary.simpleMessage("帳號已被鎖住,請15分鐘後再試"),
"accountNull": MessageLookupByLibrary.simpleMessage("請輸入帳號"),
"accountPasswordError": MessageLookupByLibrary.simpleMessage("帳號密碼錯誤"),
"aduit": MessageLookupByLibrary.simpleMessage("隨班附讀"),
"aestheticDimension": MessageLookupByLibrary.simpleMessage("美學向度"),
"alertError": MessageLookupByLibrary.simpleMessage("發生錯誤"),
"androidPrivateBrowseGuideSubTitle": MessageLookupByLibrary.simpleMessage("開啟隱私瀏覽,安全更有保障"),
Expand Down Expand Up @@ -120,6 +121,8 @@ class MessageLookup extends MessageLookupByLibrary {
"getCalendar": MessageLookupByLibrary.simpleMessage("取得行事曆中..."),
"getCalendarError": MessageLookupByLibrary.simpleMessage("取得行事曆錯誤"),
"getCourse": MessageLookupByLibrary.simpleMessage("取得課表..."),
"getCourseClassmateList": MessageLookupByLibrary.simpleMessage("獲取學生名單中..."),
"getCourseClassmateListError": MessageLookupByLibrary.simpleMessage("獲取學生名單錯誤"),
"getCourseDetail": MessageLookupByLibrary.simpleMessage("課程資料讀取中..."),
"getCourseDetailError": MessageLookupByLibrary.simpleMessage("課程資料讀取錯誤"),
"getCourseError": MessageLookupByLibrary.simpleMessage("取得課表錯誤"),
Expand Down Expand Up @@ -175,6 +178,8 @@ class MessageLookup extends MessageLookupByLibrary {
"logout": MessageLookupByLibrary.simpleMessage("登出"),
"logoutWarning": MessageLookupByLibrary.simpleMessage("確定要登出嗎? \n將會清除所有資料"),
"missingRequiredInformation": MessageLookupByLibrary.simpleMessage("缺少必要資訊"),
"name": MessageLookupByLibrary.simpleMessage("姓名"),
"nationalTaipeiUniversity": MessageLookupByLibrary.simpleMessage("國立臺北大學"),
"naturalDimension": MessageLookupByLibrary.simpleMessage("自然向度"),
"needsVerifyMobileWarning": MessageLookupByLibrary.simpleMessage("您可能被要求進行手機號碼驗證\n請至網頁版入口網站進行查看"),
"networkError": MessageLookupByLibrary.simpleMessage("網路發生錯誤"),
Expand Down Expand Up @@ -255,10 +260,12 @@ class MessageLookup extends MessageLookupByLibrary {
"sociologicalDimension": MessageLookupByLibrary.simpleMessage("社哲向度"),
"sortBy": MessageLookupByLibrary.simpleMessage("排序"),
"startClass": MessageLookupByLibrary.simpleMessage("開課班級"),
"studentId": MessageLookupByLibrary.simpleMessage("學號"),
"studentList": MessageLookupByLibrary.simpleMessage("學生清單"),
"subscribe": MessageLookupByLibrary.simpleMessage("訂閱"),
"sure": MessageLookupByLibrary.simpleMessage("確定"),
"syllabus": MessageLookupByLibrary.simpleMessage("教學大綱"),
"taipeiMedicineUniversity": MessageLookupByLibrary.simpleMessage("臺北醫學大學"),
"takeCore": MessageLookupByLibrary.simpleMessage("實得核心"),
"takeForeignDepartmentCredits": MessageLookupByLibrary.simpleMessage("外系學分"),
"takeForeignDepartmentCreditsLimit": MessageLookupByLibrary.simpleMessage("學分上限"),
Expand All @@ -270,8 +277,10 @@ class MessageLookup extends MessageLookupByLibrary {
"titleScore": MessageLookupByLibrary.simpleMessage("成績"),
"totalAverage": MessageLookupByLibrary.simpleMessage("總平均"),
"totalPeople": MessageLookupByLibrary.simpleMessage("總人數"),
"unknownDepartment": MessageLookupByLibrary.simpleMessage("未知系所"),
"unknownError": MessageLookupByLibrary.simpleMessage("發生未知錯誤"),
"unknownServerError": MessageLookupByLibrary.simpleMessage("與校園系統溝通時發生問題,大部分功能可能將受影響\n請確認校園系統能正常使用後再試一次,謝謝"),
"unknownStudent": MessageLookupByLibrary.simpleMessage("未知學生"),
"update": MessageLookupByLibrary.simpleMessage("更新"),
"useOldPassword": MessageLookupByLibrary.simpleMessage("延長原始密碼時間"),
"versionInfo": MessageLookupByLibrary.simpleMessage("版本資訊"),
Expand Down
90 changes: 90 additions & 0 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,14 @@
"androidPrivateBrowseGuideTitle": "About Incognito Browse",
"androidPrivateBrowseGuideSubTitle": "Open Incognito browsing to enhanced security",
"kClass": "class",
"kDepartment": "department"
"kDepartment": "department",
"unknownDepartment": "Unknown Department",
"unknownStudent": "Unknown Student",
"name": "name",
"studentId": "student id",
"getCourseClassmateList": "Getting classmate list...",
"getCourseClassmateListError": "Get classmate list error",
"nationalTaipeiUniversity": "NTPU",
"taipeiMedicineUniversity": "TMU",
"aduit": "Aduit"
}
11 changes: 10 additions & 1 deletion lib/l10n/intl_zh_TW.arb
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,14 @@
"androidPrivateBrowseGuideTitle": "關於隱私瀏覽",
"androidPrivateBrowseGuideSubTitle": "開啟隱私瀏覽,安全更有保障",
"kClass": "班級",
"kDepartment": "系所"
"kDepartment": "系所",
"unknownDepartment": "未知系所",
"unknownStudent": "未知學生",
"name": "姓名",
"studentId": "學號",
"getCourseClassmateList": "獲取學生名單中...",
"getCourseClassmateListError": "獲取學生名單錯誤",
"nationalTaipeiUniversity": "國立臺北大學",
"taipeiMedicineUniversity": "臺北醫學大學",
"aduit": "隨班附讀"
}
110 changes: 110 additions & 0 deletions lib/src/connector/course_connector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter_app/src/connector/ntut_connector.dart';
import 'package:flutter_app/src/model/course/course_class_json.dart';
import 'package:flutter_app/src/model/course/course_main_extra_json.dart';
import 'package:flutter_app/src/model/course/course_score_json.dart';
import 'package:flutter_app/src/model/course/course_syllabus_json.dart';
import 'package:flutter_app/src/model/coursetable/course_table_json.dart';
import 'package:html/dom.dart';
import 'package:html/parser.dart';
Expand All @@ -24,9 +25,11 @@ class CourseConnector {
static const String _courseCNHost = "https://aps.ntut.edu.tw/course/tw/";
static const String _courseENHost = "https://aps.ntut.edu.tw/course/en/";
static const String _postCourseCNUrl = "${_courseCNHost}Select.jsp";
static const String _getSyllabusCNUrl = "${_courseCNHost}ShowSyllabus.jsp";
static const String _postTeacherCourseCNUrl = "${_courseCNHost}Teach.jsp";
static const String _postCourseENUrl = "${_courseENHost}Select.jsp";
static const String _creditUrl = "${_courseCNHost}Cprog.jsp";
static const String _getCourseDepartmentUrl = "${_courseCNHost}Subj.jsp";

static Future<CourseConnectorStatus> login() async {
String result;
Expand Down Expand Up @@ -62,6 +65,78 @@ class CourseConnector {
}
}

// It should use code with key (59 -> CSIE, 32 -> Electric), and department name with value.
static Future<Map<String, String>> getDepartmentMap(String year, String semester) async {
try {
ConnectorParameter parameter = ConnectorParameter(_getCourseDepartmentUrl);
parameter.data = {"format": "-2", "year": year, "sem": semester};
String result = await Connector.getDataByGet(parameter);

Document tagNode = parse(result);
List<Element> departmentNodes = tagNode.getElementsByTagName("a");

Map<String, String> departmentMap = {};
for (Element element in departmentNodes) {
final href = element.attributes["href"];
if (href.isEmpty) {
continue;
}
String codeParameter = href.split("&").firstWhere((parameter) => parameter.contains("code"), orElse: () => "");
if (codeParameter == "") {
continue;
}
String code = codeParameter.split("=")[1];
String departmentName = element.text;
departmentMap.putIfAbsent(code, () => departmentName);
}

return departmentMap;
} catch (e, stack) {
Log.eWithStack(e, stack);
return null;
}
}

static Future<Map<String, String>> getTwoYearUndergraduateDepartmentMap(String year) async {
try {
ConnectorParameter parameter = ConnectorParameter(_creditUrl);
parameter.data = {"format": "-3", "year": year, "matric": "6"};
String result = await Connector.getDataByGet(parameter);

Document tagNode = parse(result);
List<Element> departmentNodes = tagNode.getElementsByTagName("a");

Map<String, String> departmentMap = {};
for (Element element in departmentNodes) {
final href = element.attributes["href"];
if (href.isEmpty) {
continue;
}
String divisionParameter =
href.split("&").firstWhere((parameter) => parameter.contains("division"), orElse: () => "");
if (divisionParameter == "") {
continue;
}
final String code = divisionParameter.split("=")[1];
final RegExp regExp = RegExp(".+【(.+)】");
final RegExpMatch matches = regExp.firstMatch(element.text);
if (matches == null || matches.groupCount == 0) {
continue;
}
final departmentName = matches.group(1);
if (departmentName.isEmpty) {
continue;
}
departmentMap.putIfAbsent(code, () => departmentName);
}

return departmentMap;
} catch (e, stack) {
Log.eWithStack(e, stack);
return null;
}
}

static Future<String> getCourseENName(String url) async {
try {
ConnectorParameter parameter;
Expand Down Expand Up @@ -163,6 +238,41 @@ class CourseConnector {
}
}

static Future<CourseSyllabusJson> getCourseCategory(String courseId) async {
try {
Map<String, String> data = {
"snum": courseId,
};
ConnectorParameter parameter = ConnectorParameter(_getSyllabusCNUrl);
parameter.data = data;
String result = await Connector.getDataByGet(parameter);
Document tagNode = parse(result);

var tables = tagNode.getElementsByTagName("table");
var trs = tables[0].getElementsByTagName("tr");
var syllabusRow = trs[1].getElementsByTagName("td");

var model = CourseSyllabusJson(
yearSemester: syllabusRow[0].text,
courseId: syllabusRow[1].text,
courseName: syllabusRow[2].text,
phase: syllabusRow[3].text,
credit: syllabusRow[4].text,
hour: syllabusRow[5].text,
category: syllabusRow[6].text,
teachers: syllabusRow[7].text,
className: syllabusRow[8].text,
applyStudentCount: syllabusRow[9].text,
withdrawStudentCount: syllabusRow[10].text,
note: syllabusRow[11].text);

return model;
} catch (e, stack) {
Log.eWithStack(e.toString(), stack);
return CourseSyllabusJson();
}
}

static Future<List<SemesterJson>> getCourseSemester(String studentId) async {
try {
ConnectorParameter parameter;
Expand Down
Loading

0 comments on commit 23ff926

Please sign in to comment.