From adc98fa0d5bdfcd7ea297bf362b0d9626404404f Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Wed, 3 Oct 2018 23:08:57 +0300 Subject: [PATCH] finish shout parsing --- .../main/shoutbox/ShoutboxFragment.java | 7 ++++ .../main/shoutbox/ShoutboxTask.java | 42 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java create mode 100644 app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxTask.java diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java new file mode 100644 index 00000000..25d659cc --- /dev/null +++ b/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 { + +} diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxTask.java new file mode 100644 index 00000000..88dad072 --- /dev/null +++ b/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> { + @Override + protected ArrayList 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 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 = "" + + ParseHelpers.youtubeEmbeddedFix(content); + shouts.add(new Shout(profileName, profileUrl, dateString, shoutContent)); + } + return shouts; + } + + @Override + protected int getResultCode(Response response, ArrayList data) { + return 0; + } +}