aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java
diff options
context:
space:
mode:
authorBryson Steck <steck.bryson@gmail.com>2021-05-04 17:59:55 -0600
committerBryson Steck <steck.bryson@gmail.com>2021-05-04 17:59:55 -0600
commit99643e5be84af7e8da217ed48597ceb3c9d3bc85 (patch)
tree91c314dc3a0f4b60d731ccb8854869302eb9bd8d /app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java
parentaf7a395b8c707fe5be3c03e9de878fae1d16b997 (diff)
downloadwiimmfi-watcher-99643e5be84af7e8da217ed48597ceb3c9d3bc85.tar
wiimmfi-watcher-99643e5be84af7e8da217ed48597ceb3c9d3bc85.tar.gz
wiimmfi-watcher-99643e5be84af7e8da217ed48597ceb3c9d3bc85.tar.bz2
before i get too deep in the database stuff
Diffstat (limited to 'app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java')
-rw-r--r--app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java134
1 files changed, 134 insertions, 0 deletions
diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java
new file mode 100644
index 0000000..2fccffc
--- /dev/null
+++ b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java
@@ -0,0 +1,134 @@
+package com.example.wiimmterfaceandroid.wiimmfi;
+
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+public class RoomData {
+ String roomHeader;
+ String playerLink;
+ String friendCode;
+ ArrayList<Player> players = new ArrayList<>();
+
+ public RoomData (ArrayList<Player> players, String playerLink, String friendCode) {
+ this.playerLink = getPlayerLink();
+ this.friendCode = friendCode;
+ Document doc = null;
+
+ if (playerLink == null) {
+ System.out.println("The player link is null for some reason");
+ } else {
+
+ try {
+ doc = Jsoup.connect("https://wiimmfi.de/" + this.playerLink).get();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ Element table = doc.select("table").get(0);
+ Elements rows = table.select("tr");
+
+ for (int i = 0; i < rows.size(); i++) {
+ Element row = rows.get(i);
+ Elements colPlayers = row.select("td");
+ Elements colHeader = row.select("th");
+
+ if (colHeader.size() > 0) {
+ if (!colHeader.get(0).text().equals("friend code")) {
+ roomHeader = colHeader.get(0).text();
+ }
+ }
+ if (colPlayers.size() > 0) {
+
+ Player currentPlayer = new Player();
+ for (int j = 0; j < colPlayers.size(); j++) {
+ System.out.println("Player Data: " + colPlayers.get(j).text());
+ switch (j) {
+ case 0:
+ currentPlayer.friendCode = colPlayers.get(0).text();
+ break;
+ case 1:
+ currentPlayer.role = colPlayers.get(1).text().split(" ")[1];
+ currentPlayer.rosterNumber = colPlayers.get(1).text().split(" ")[0].replaceAll("\\s", "");
+ break;
+ case 2:
+ currentPlayer.loginRegion = colPlayers.get(2).text();
+ break;
+ case 3:
+ currentPlayer.roomMatch = colPlayers.get(3).text();
+ break;
+ case 4:
+ currentPlayer.world = colPlayers.get(4).text();
+ break;
+ case 5:
+ currentPlayer.connFail = colPlayers.get(5).text();
+ break;
+ case 6:
+ currentPlayer.vr = colPlayers.get(6).text();
+ break;
+ case 7:
+ currentPlayer.br = colPlayers.get(7).text();
+ break;
+ case 8:
+ currentPlayer.miiName = colPlayers.get(8).text();
+ break;
+ }
+ }
+ if (currentPlayer.friendCode.equals(friendCode)) {
+ currentPlayer.watching = true;
+ }
+ players.add(currentPlayer);
+ }
+
+ }
+ }
+ }
+
+ public String getPlayerLink() {
+ try {
+ Document doc = null;
+
+ doc = Jsoup.connect("https://wiimmfi.de/stats/mkw").get();
+ Element table = doc.select("table").get(0);
+ Elements rows = table.select("tr");
+
+ for (int i = 0; i < rows.size(); i++) {
+ Element row = rows.get(i);
+ Elements colPlayers = row.select("td");
+ Elements colHeader = row.select("th");
+
+
+ if (colPlayers.size() > 0) {
+
+ String data = colPlayers.get(0).select("a").toString();
+// System.out.println(data);
+ if (data.contains(friendCode)) {
+ System.out.println("Found friend code");
+ playerLink = data.split("\"")[3];
+ System.out.println("Player link: " + playerLink);
+
+ }
+ }
+ }
+
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return playerLink;
+ }
+ public ArrayList<Player> getPlayers() { return players; }
+
+ public String getRoomHeader() { return this.roomHeader; }
+
+ public RoomData refresh() {
+ players.clear();
+ roomHeader = "";
+ RoomData returningData = new RoomData(players, playerLink, friendCode);
+ return returningData;
+ }
+}
+