Advertisement
Guest User

Untitled

a guest
May 26th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. package com.example.johan.mini_projekt;
  2.  
  3. import android.graphics.Color;
  4. import android.support.constraint.ConstraintLayout;
  5. import android.widget.TableLayout;
  6. import android.widget.TableRow;
  7. import android.widget.TextView;
  8.  
  9. import org.jsoup.nodes.Document;
  10. import org.jsoup.*;
  11. import org.jsoup.nodes.Element;
  12. import org.jsoup.select.Elements;
  13.  
  14. import java.io.IOException;
  15. import java.util.ArrayList;
  16.  
  17. public class parser {
  18. private Document doc = null;
  19.  
  20. private String getURL (String year, String value, boolean forTeam) {
  21. if(forTeam) {
  22. return "http://teamplaycup.se/cup/?games&home=kurirenspelen/" + year + "&scope=all&arena=" + value + "&field=";
  23. } else {
  24. return "http://teamplaycup.se/cup/?overviewgroup&home=kurirenspelen/" + year + "&scope=" + value;
  25. }
  26. }
  27.  
  28. public ArrayList<ArrayList<String>> getMatches(final String year, final String arena) throws IOException {
  29.  
  30. Thread getThread = new Thread() {
  31. public void run() {
  32. doc = null;
  33.  
  34. try {
  35. doc = Jsoup.connect(getURL(year, arena, true)).get();
  36. } catch (IOException e) {
  37. e.printStackTrace();
  38. }
  39.  
  40. }
  41. };
  42. getThread.start();
  43.  
  44. while (doc == null) {
  45.  
  46. }
  47.  
  48. Elements titles = doc.getElementsByTag("h4");
  49. Elements tables = doc.getElementsByTag("tbody");
  50.  
  51. ArrayList<ArrayList<String>> games = new ArrayList<ArrayList<String>>();
  52.  
  53. int index = 0;
  54. for (Element title : titles) {
  55.  
  56. Elements curGames = tables.get(index).children();
  57.  
  58. for (Element curGame : curGames) {
  59. ArrayList<String> match = new ArrayList<String>();
  60. Elements attr = curGame.children();
  61.  
  62. match.add(title.text()); //Date
  63. match.add(attr.get(0).children().get(0).text()); //Match number
  64. match.add(attr.get(1).children().get(0).text()); //Group
  65. match.add(attr.get(2).text()); //Time
  66. match.add(attr.get(3).children().get(0).text()); //Team 1 name
  67. match.add(attr.get(3).children().get(0).attr("href")); //Team 1 link
  68. match.add(attr.get(3).children().get(1).text()); //Team 2 name
  69. match.add(attr.get(3).children().get(1).attr("href")); //Team 2 link
  70.  
  71. games.add(match);
  72. }
  73.  
  74.  
  75.  
  76. index++;
  77. }
  78.  
  79. return games;
  80. }
  81.  
  82. public ArrayList<ArrayList<String>> getPlayers(final String url) throws IOException {
  83.  
  84. Thread getThread = new Thread() {
  85. public void run() {
  86. doc = null;
  87.  
  88. try {
  89. doc = Jsoup.connect(url).get();
  90. } catch (IOException e) {
  91. e.printStackTrace();
  92. }
  93.  
  94. }
  95. };
  96. getThread.start();
  97.  
  98. while (doc == null) {
  99.  
  100. }
  101.  
  102. Element table = doc.getElementsByTag("tbody").get(0);
  103. ArrayList<ArrayList<String>> players = new ArrayList<ArrayList<String>>();
  104.  
  105. for (Element playerElement : table.children()) {
  106. ArrayList<String> player = new ArrayList<String>();
  107.  
  108. player.add(playerElement.children().get(0).text()); //Name
  109. player.add(playerElement.children().get(1).text()); //Birth date
  110. players.add(player);
  111. }
  112.  
  113. return players;
  114. }
  115.  
  116. public String getAge(final String year, final String group) throws IOException {
  117.  
  118. Thread getThread = new Thread() {
  119. public void run() {
  120. doc = null;
  121.  
  122. try {
  123. doc = Jsoup.connect(getURL(year, group, false)).get();
  124. } catch (IOException e) {
  125. e.printStackTrace();
  126. }
  127.  
  128. }
  129. };
  130. getThread.start();
  131.  
  132. while (doc == null) {
  133.  
  134. }
  135.  
  136. String groupString = doc.getElementsByTag("h2").get(0).text();
  137.  
  138. String age;
  139. if(groupString.substring(0,1) == "P") {
  140. age = groupString.substring(7,9);
  141. } else {
  142. age = groupString.substring(8,10);
  143. }
  144.  
  145. return age;
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement