Skip to content

Commit

Permalink
Fix midterm alert empty index error
Browse files Browse the repository at this point in the history
  • Loading branch information
abc873693 committed Aug 28, 2020
1 parent 642c742 commit bd0e0b5
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions lib/api/parser/ap_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,29 +304,30 @@ Map<String, dynamic> midtermAlertsParser(String html) {
Map<String, dynamic> data = {"courses": []};

var document = parse(html);
var table =
document.getElementsByTagName("table")[1].getElementsByTagName("tr");
try {
for (int i = 1; i < table.length; i++) {
var tdData = table[i].getElementsByTagName("td");
if (tdData.length < 5) {
continue;
}
if (tdData[5].text[0] == "是") {
data["courses"].add({
"entry": tdData[0].text,
"className": tdData[1].text,
"title": tdData[2].text,
"group": tdData[3].text,
"instructors": tdData[4].text,
"reason": tdData[6].text,
"remark": tdData[7].text
});
var table = document.getElementsByTagName("table");
if (table.length > 1)
try {
final td = table[1].getElementsByTagName("tr");
for (int i = 1; i < td.length; i++) {
var tdData = td[i].getElementsByTagName("td");
if (tdData.length < 5) {
continue;
}
if (tdData[5].text[0] == "是") {
data["courses"].add({
"entry": tdData[0].text,
"className": tdData[1].text,
"title": tdData[2].text,
"group": tdData[3].text,
"instructors": tdData[4].text,
"reason": tdData[6].text,
"remark": tdData[7].text
});
}
}
} on Exception catch (e) {
print(e);
}
} on Exception catch (e) {
print(e);
}
return data;
}

Expand Down

0 comments on commit bd0e0b5

Please sign in to comment.