Browse Source

finish shout parsing

pull/61/merge
Thodoris1999 6 years ago
parent
commit
adc98fa0d5
  1. 7
      app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java
  2. 42
      app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxTask.java

7
app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java

@ -0,0 +1,7 @@
package gr.thmmy.mthmmy.activities.main.shoutbox;
import gr.thmmy.mthmmy.base.BaseFragment;
public class ShoutboxFragment extends BaseFragment {
}

42
app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxTask.java

@ -0,0 +1,42 @@
package gr.thmmy.mthmmy.activities.main.shoutbox;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.util.ArrayList;
import gr.thmmy.mthmmy.model.Shout;
import gr.thmmy.mthmmy.utils.parsing.NewParseTask;
import gr.thmmy.mthmmy.utils.parsing.ParseException;
import gr.thmmy.mthmmy.utils.parsing.ParseHelpers;
import okhttp3.Response;
public class ShoutboxTask extends NewParseTask<ArrayList<Shout>> {
@Override
protected ArrayList<Shout> parse(Document document, Response response) throws ParseException {
// shout container: document.select("div[class=smalltext]" && div.text().contains("Τελευταίες 75 φωνές:") η στα αγγλικα
Element shoutboxContainer = document.select("div[style=width: 99%; height: 600px; overflow: auto;]").first();
ArrayList<Shout> shouts = new ArrayList<>();
for (Element shout : shoutboxContainer.children()) {
Element user = shout.child(0);
Element link = user.select("a").first();
String profileUrl = link.attr("href");
String profileName = link.text();
Element date = shout.child(1);
String dateString = date.text();
Element content = shout.child(2);
String shoutContent = "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />" +
ParseHelpers.youtubeEmbeddedFix(content);
shouts.add(new Shout(profileName, profileUrl, dateString, shoutContent));
}
return shouts;
}
@Override
protected int getResultCode(Response response, ArrayList<Shout> data) {
return 0;
}
}
Loading…
Cancel
Save