You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
161 lines
5.6 KiB
161 lines
5.6 KiB
package jsoupImport;
|
|
|
|
import functions.*;
|
|
import objects.Player;
|
|
import objects.Stat;
|
|
|
|
import org.jsoup.Jsoup;
|
|
import org.jsoup.nodes.Document;
|
|
import org.jsoup.nodes.Element;
|
|
import org.jsoup.select.Elements;
|
|
import org.openqa.selenium.By;
|
|
import org.openqa.selenium.support.ui.ExpectedConditions;
|
|
|
|
import call_pages.CALL_Fantasy;
|
|
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
|
|
/**
|
|
* Created by LeJay on 19.02.2017.
|
|
*/
|
|
|
|
public class ImportPlayers extends CALL_Fantasy {//called from MainActivity
|
|
|
|
public ImportPlayers() {
|
|
|
|
//new Thread(new Runnable() {
|
|
// public void run() {
|
|
|
|
String title;
|
|
int nbStat;
|
|
|
|
//dbHandler = new DB_handler(context); //need to be in async
|
|
|
|
Document doc;
|
|
for (int t = 0; t < l1.nbTeams; t++) {
|
|
|
|
//create list of player
|
|
l1.leagueTeams.get(t).players = new ArrayList<Player>();
|
|
|
|
driver.get("http://fantasy.espn.com/basketball/team?leagueId=" + l1.getCode() +
|
|
"&teamId=" + l1.leagueTeams.get(t).getID() + "&statSplit=currSeason");// + "&seasonId=" + l1.getSeason() +
|
|
//"&scoringPeriodId=" + l1.getNbDaysPlayed() + "&statSplit=singleScoringPeriodn");
|
|
|
|
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='jsx-2810852873 table--cell opp ml4']")));// instead of id u can use cssSelector or xpat
|
|
String content = driver.getPageSource();
|
|
|
|
doc = Jsoup.parse(content);
|
|
|
|
// get page title
|
|
title = doc.title();
|
|
System.out.println("title : " + title);
|
|
|
|
//select player name table
|
|
Element tablePlayer = doc.select("table.Table2__right-aligned.Table2__table-fixed.Table2__Table--fixed--left.Table2__table").get(0); //select the first table.
|
|
Elements rowsPlayer = tablePlayer.select("tr");
|
|
Element rowPlayer;
|
|
Elements colsPlayer;
|
|
|
|
//select stat table
|
|
Element tableStat = doc.select("table.Table2__table-scroller.Table2__right-aligned.Table2__table").get(0); //select the first table.
|
|
Elements rowsStat = tableStat.select("tr");
|
|
Element rowStat;
|
|
Elements colsStat;
|
|
|
|
int nbPlayer = 0;
|
|
// go through players list
|
|
for (int i = 2; i < rowsPlayer.size(); i++) { //first row is the col names so skip it.
|
|
|
|
rowPlayer = rowsPlayer.get(i);
|
|
colsPlayer = rowPlayer.select("td");
|
|
|
|
rowStat = rowsStat.get(i);
|
|
colsStat = rowStat.select("td");
|
|
|
|
String log = "";
|
|
|
|
// System.out.println(cols.get(0).text());
|
|
// for (int k = 0; k < cols.size(); k++) {
|
|
// log += "/" + cols.get(k).text();
|
|
// }
|
|
// System.out.println(log);
|
|
|
|
if (!colsPlayer.get(1).text().equals("Empty") && !colsPlayer.get(1).text().equals("")) {
|
|
|
|
|
|
// le nom
|
|
String word = colsPlayer.select("a.link.clr-link.pointer").get(0).text();
|
|
String nomFranchise = colsPlayer.select("span.playerinfo__playerteam").get(0).text();
|
|
String[] positions = colsPlayer.select("span.playerinfo__playerpos.ttu").get(0).text().split(", ");
|
|
|
|
l1.leagueTeams.get(t).players.add(new Player(word));
|
|
|
|
int tt = l1.leagueTeams.get(t).players.size();
|
|
Player player = l1.leagueTeams.get(t).players.get(tt-1);
|
|
player.setPositions(positions);
|
|
player.setFranchise(nomFranchise);
|
|
|
|
//-----------------------------------------------Create a copy of Stat list
|
|
ArrayList<Stat> loadStat = new ArrayList<Stat>();
|
|
nbStat = 0;
|
|
int nbSpace=0;
|
|
for (int k = 1; k < colsStat.size()-1; k++) { //first row is the col names so skip it.
|
|
System.out.println(colsStat.get(k).text());
|
|
if (!colsStat.get(k).text().replaceAll("\\s","").equals("")) {
|
|
loadStat.add(new Stat(l1.loadStatBasePlayer.get(nbStat-nbSpace).getName()));
|
|
loadStat.get(nbStat-nbSpace).setStatVal(colsStat.get(k-nbSpace).text());
|
|
}else{
|
|
nbSpace++;
|
|
}
|
|
nbStat += 1;
|
|
|
|
if(nbStat > l1.loadStatBasePlayer.size()){break;};
|
|
}
|
|
//ajoute les stats au joueur apres l avoir cr��
|
|
player.setStats(loadStat);
|
|
player.setIsFA(false);
|
|
player.teamID = l1.leagueTeams.get(t).getID();
|
|
player.setOrgTeamID(l1.leagueTeams.get(t).getID());
|
|
|
|
l1.leaguePlayers.add(player);
|
|
|
|
nbPlayer += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
System.out.println("yo");
|
|
|
|
RANKS_fill.fillPlayerRKinTeamOWN(l1.leagueTeams.get(t));
|
|
|
|
}//end loop team
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/*@Override
|
|
protected void onPostExecute(Void result) {
|
|
|
|
SHOW_tab.printTeams();
|
|
|
|
//projection need actual total attempt / made just calculated
|
|
btn_Proj.setEnabled(true);
|
|
|
|
// Fragment f = getFragmentManager().findFragmentById(R.id.frag_teams);
|
|
// if(f != null){
|
|
// for(Teams teams : l1.leagueTeams){
|
|
// FragmentTeams.btn_teams[teams.getCode()].setEnabled(true);
|
|
// }
|
|
// }
|
|
|
|
PROJ_analysis.calculate();
|
|
|
|
//mProgressDialog.dismiss();
|
|
}*/
|
|
// }).start();
|
|
//}
|
|
}
|
|
|