Browse Source

Include edge cases in BoardActivity parsing

pull/70/head
Ezerous 5 years ago
parent
commit
43567e03b5
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 23
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java

23
app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java

@ -229,6 +229,9 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
if (newTopicButton == null) if (newTopicButton == null)
newTopicButton = boardPage.select("a:has(img[alt=Νέο θέμα])").first(); newTopicButton = boardPage.select("a:has(img[alt=Νέο θέμα])").first();
if (newTopicButton != null) newTopicUrl = newTopicButton.attr("href"); if (newTopicButton != null) newTopicUrl = newTopicButton.attr("href");
final Pattern pLastPostPattern = Pattern.compile("((?:(?!(?:by|από)).)*)\\s(?:by|από)\\s(.*)");
if(pagesLoaded == 0) { //Finds sub boards if(pagesLoaded == 0) { //Finds sub boards
Elements subBoardRows = boardPage.select("div.tborder>table>tbody>tr"); Elements subBoardRows = boardPage.select("div.tborder>table>tbody>tr");
if (subBoardRows != null && !subBoardRows.isEmpty()) { if (subBoardRows != null && !subBoardRows.isEmpty()) {
@ -253,12 +256,25 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
if (matcher.find()){ if (matcher.find()){
String pLastPostDateTime = matcher.group(1); String pLastPostDateTime = matcher.group(1);
String pSubject = subBoardCol.select("a").first().attr("title"); String pSubject = subBoardCol.select("a").first().attr("title");
String pLastUser = subBoardCol.select("a").last().text();
// Purification for extreme edge cases
String pSubjectConcat = subBoardCol.select("a").first().text();
pLastPost = pLastPost.replaceAll(pSubjectConcat, "");
String pLastUser;
matcher = pLastPostPattern.matcher(pLastPost); //Don't even try simply grabbing <a>, user might be guest
if (matcher.find())
pLastUser = matcher.group(2);
else {
parsingFailed = true;
break;
}
pLastPost = "Last post on: " + pLastPostDateTime + "\nin: " + pSubject + "\nby " +pLastUser; pLastPost = "Last post on: " + pLastPostDateTime + "\nin: " + pSubject + "\nby " +pLastUser;
pLastPostUrl = subBoardCol.select("a").first().attr("href"); pLastPostUrl = subBoardCol.select("a").first().attr("href");
} }
else{ else {
parsingFailed = true; parsingFailed = true;
break; break;
} }
@ -306,8 +322,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
pStats = "Replies: " + topicColumns.get(4).text() + ", Views: " + topicColumns.get(5).text(); pStats = "Replies: " + topicColumns.get(4).text() + ", Views: " + topicColumns.get(5).text();
pLastPost = topicColumns.last().text(); pLastPost = topicColumns.last().text();
Pattern pattern = Pattern.compile("((?:(?!(?:by|από)).)*)\\s(?:by|από)\\s(.*)"); Matcher matcher = pLastPostPattern.matcher(pLastPost);
Matcher matcher = pattern.matcher(pLastPost);
if (matcher.find()){ if (matcher.find()){
pLastPostDateTime = matcher.group(1); pLastPostDateTime = matcher.group(1);
pLastUser = matcher.group(2); pLastUser = matcher.group(2);

Loading…
Cancel
Save