|
@@ -22,6 +22,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
|
|
|
import com.google.common.base.Strings;
|
|
import com.google.common.base.Strings;
|
|
|
|
|
|
|
|
import mysql.Mysql;
|
|
import mysql.Mysql;
|
|
|
|
|
+import object.ResultDTO;
|
|
|
|
|
|
|
|
public class OddsPortal implements ParserJoinedFunctions {
|
|
public class OddsPortal implements ParserJoinedFunctions {
|
|
|
|
|
|
|
@@ -32,10 +33,11 @@ public class OddsPortal implements ParserJoinedFunctions {
|
|
|
private int leagueId;
|
|
private int leagueId;
|
|
|
private LocalDateTime gameDate;
|
|
private LocalDateTime gameDate;
|
|
|
|
|
|
|
|
- // https://stackoverflow.com/questions/14439991/skip-particular-javascript-execution-in-html-unit Skip url
|
|
|
|
|
|
|
+ // https://stackoverflow.com/questions/14439991/skip-particular-javascript-execution-in-html-unit
|
|
|
|
|
+ // Skip url
|
|
|
public void getMatchesByDate(String date) {
|
|
public void getMatchesByDate(String date) {
|
|
|
final String soccerUrl = "https://oddsportal.com/matches/soccer/" + date;
|
|
final String soccerUrl = "https://oddsportal.com/matches/soccer/" + date;
|
|
|
- // final String hockeyUrl = "https://oddsportal.com/matches/hockey/" + date;
|
|
|
|
|
|
|
+ // final String hockeyUrl = "https://oddsportal.com/matches/hockey/" + date;
|
|
|
|
|
|
|
|
final WebClient webClient = new WebClient();
|
|
final WebClient webClient = new WebClient();
|
|
|
webClient.getOptions().setUseInsecureSSL(true);
|
|
webClient.getOptions().setUseInsecureSSL(true);
|
|
@@ -89,7 +91,7 @@ public class OddsPortal implements ParserJoinedFunctions {
|
|
|
abandon = true;
|
|
abandon = true;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- //Score
|
|
|
|
|
|
|
+ // Score
|
|
|
if (tc.getAttribute("class").contains("table-score")) {
|
|
if (tc.getAttribute("class").contains("table-score")) {
|
|
|
final String[] scoreValue = tc.getTextContent().split(":");
|
|
final String[] scoreValue = tc.getTextContent().split(":");
|
|
|
homeScore = Integer.valueOf(scoreValue[0]);
|
|
homeScore = Integer.valueOf(scoreValue[0]);
|
|
@@ -102,17 +104,17 @@ public class OddsPortal implements ParserJoinedFunctions {
|
|
|
if (tc.getTextContent().matches("[+-][0-9][0-9][0-9]")) {
|
|
if (tc.getTextContent().matches("[+-][0-9][0-9][0-9]")) {
|
|
|
if (odds1 == 0F) {
|
|
if (odds1 == 0F) {
|
|
|
odds1 = convertAmericanOddsToDecimal(Integer.valueOf(tc.getTextContent()));
|
|
odds1 = convertAmericanOddsToDecimal(Integer.valueOf(tc.getTextContent()));
|
|
|
- } else if (oddsX == 0F ) {
|
|
|
|
|
|
|
+ } else if (oddsX == 0F) {
|
|
|
oddsX = convertAmericanOddsToDecimal(Integer.valueOf(tc.getTextContent()));
|
|
oddsX = convertAmericanOddsToDecimal(Integer.valueOf(tc.getTextContent()));
|
|
|
- } else if (odds2 == 0F ) {
|
|
|
|
|
|
|
+ } else if (odds2 == 0F) {
|
|
|
odds2 = convertAmericanOddsToDecimal(Integer.valueOf(tc.getTextContent()));
|
|
odds2 = convertAmericanOddsToDecimal(Integer.valueOf(tc.getTextContent()));
|
|
|
}
|
|
}
|
|
|
} else if (tc.getTextContent().matches("[0-9].[0-9]+")) {
|
|
} else if (tc.getTextContent().matches("[0-9].[0-9]+")) {
|
|
|
if (odds1 == 0F) {
|
|
if (odds1 == 0F) {
|
|
|
odds1 = Float.valueOf(tc.getTextContent());
|
|
odds1 = Float.valueOf(tc.getTextContent());
|
|
|
- } else if (oddsX == 0F ) {
|
|
|
|
|
|
|
+ } else if (oddsX == 0F) {
|
|
|
oddsX = Float.valueOf(tc.getTextContent());
|
|
oddsX = Float.valueOf(tc.getTextContent());
|
|
|
- } else if (odds2 == 0F ) {
|
|
|
|
|
|
|
+ } else if (odds2 == 0F) {
|
|
|
odds2 = Float.valueOf(tc.getTextContent());
|
|
odds2 = Float.valueOf(tc.getTextContent());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -120,9 +122,14 @@ public class OddsPortal implements ParserJoinedFunctions {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
} catch (final NumberFormatException e) {
|
|
} catch (final NumberFormatException e) {
|
|
|
- System.out.println("Failed to get the match between " + teams[0].trim() + " and " + teams[1].trim() + " at " +
|
|
|
|
|
- baseDate.withHour(Integer.valueOf(time[0])).withMinute(Integer.valueOf(time[1])) +
|
|
|
|
|
- " odds1: " + odds1 + " oddsX: " + oddsX + " odds2: " + odds2 + " homeScore " + homeScore + " awayScore " + awayScore + " overtime: " + (overtime?"true":"false"));
|
|
|
|
|
|
|
+ System.out
|
|
|
|
|
+ .println("Failed to get the match between " + teams[0].trim() + " and "
|
|
|
|
|
+ + teams[1].trim() + " at "
|
|
|
|
|
+ + baseDate.withHour(Integer.valueOf(time[0]))
|
|
|
|
|
+ .withMinute(Integer.valueOf(time[1]))
|
|
|
|
|
+ + " odds1: " + odds1 + " oddsX: " + oddsX + " odds2: " + odds2 + " homeScore "
|
|
|
|
|
+ + homeScore + " awayScore " + awayScore + " overtime: "
|
|
|
|
|
+ + (overtime ? "true" : "false"));
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -140,8 +147,10 @@ public class OddsPortal implements ParserJoinedFunctions {
|
|
|
season = String.valueOf(LocalDateTime.now().getYear());
|
|
season = String.valueOf(LocalDateTime.now().getYear());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- final LocalDateTime dt = baseDate.withHour(Integer.valueOf(time[0])).withMinute(Integer.valueOf(time[1])).withSecond(0).withNano(0);
|
|
|
|
|
- mysql.addResult("SoccerResults", dt, teams[0].trim(), teams[1].trim(), homeScore, awayScore, overtime, odds1, oddsX, odds2, countryId, season, leagueId, sportId);
|
|
|
|
|
|
|
+ final LocalDateTime dt = baseDate.withHour(Integer.valueOf(time[0]))
|
|
|
|
|
+ .withMinute(Integer.valueOf(time[1])).withSecond(0).withNano(0);
|
|
|
|
|
+ mysql.addResult(new ResultDTO("SoccerResults", dt, teams[0].trim(), teams[1].trim(), homeScore,
|
|
|
|
|
+ awayScore, overtime, odds1, oddsX, odds2, countryId, season, leagueId, sportId));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} catch (FailingHttpStatusCodeException | IOException e) {
|
|
} catch (FailingHttpStatusCodeException | IOException e) {
|
|
@@ -182,11 +191,12 @@ public class OddsPortal implements ParserJoinedFunctions {
|
|
|
leagueId = mysql.getLeagueId(sportId, countryId, league);
|
|
leagueId = mysql.getLeagueId(sportId, countryId, league);
|
|
|
String season = "";
|
|
String season = "";
|
|
|
|
|
|
|
|
- final HtmlPage leaguePage = webClient.getPage(url + "/" + sport + "/" + country + "/" + league + urlYearPart + resultsPage);
|
|
|
|
|
|
|
+ final HtmlPage leaguePage = webClient
|
|
|
|
|
+ .getPage(url + "/" + sport + "/" + country + "/" + league + urlYearPart + resultsPage);
|
|
|
final List<HtmlAnchor> yearFilter = leaguePage.getByXPath("//ul[contains(@class,'main-filter')]//a");
|
|
final List<HtmlAnchor> yearFilter = leaguePage.getByXPath("//ul[contains(@class,'main-filter')]//a");
|
|
|
for (final HtmlAnchor a : yearFilter) {
|
|
for (final HtmlAnchor a : yearFilter) {
|
|
|
System.out.println("Year filter: " + a.getHrefAttribute());
|
|
System.out.println("Year filter: " + a.getHrefAttribute());
|
|
|
- final String active = ((HtmlSpan)a.getParentNode().getParentNode()).getAttribute("class");
|
|
|
|
|
|
|
+ final String active = ((HtmlSpan) a.getParentNode().getParentNode()).getAttribute("class");
|
|
|
if (active.contains("active") && !active.contains("inactive")) {
|
|
if (active.contains("active") && !active.contains("inactive")) {
|
|
|
season = a.getTextContent();
|
|
season = a.getTextContent();
|
|
|
year = season.replace('/', '-');
|
|
year = season.replace('/', '-');
|
|
@@ -200,7 +210,8 @@ public class OddsPortal implements ParserJoinedFunctions {
|
|
|
final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd MMM yyyy", Locale.ENGLISH);
|
|
final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd MMM yyyy", Locale.ENGLISH);
|
|
|
parseTournamentTable(sportId, countryId, leagueId, season, tournamentTable, gameDate, dateFormatter);
|
|
parseTournamentTable(sportId, countryId, leagueId, season, tournamentTable, gameDate, dateFormatter);
|
|
|
final HtmlDivision paginationLinksDiv = (HtmlDivision) tournamentTableDiv.getLastChild();
|
|
final HtmlDivision paginationLinksDiv = (HtmlDivision) tournamentTableDiv.getLastChild();
|
|
|
- final List<HtmlAnchor> pagiantionLinks = paginationLinksDiv.getByXPath(".//a[contains(@href, 'page') and not(.//span[contains(@class, 'arrow')])]");
|
|
|
|
|
|
|
+ final List<HtmlAnchor> pagiantionLinks = paginationLinksDiv
|
|
|
|
|
+ .getByXPath(".//a[contains(@href, 'page') and not(.//span[contains(@class, 'arrow')])]");
|
|
|
for (final HtmlAnchor a : pagiantionLinks) {
|
|
for (final HtmlAnchor a : pagiantionLinks) {
|
|
|
System.out.println("Continuing with Pagination: " + a.getHrefAttribute());
|
|
System.out.println("Continuing with Pagination: " + a.getHrefAttribute());
|
|
|
// When done with start page click pagiantion
|
|
// When done with start page click pagiantion
|
|
@@ -211,7 +222,8 @@ public class OddsPortal implements ParserJoinedFunctions {
|
|
|
|
|
|
|
|
tournamentTableDiv = leaguePage.getHtmlElementById("tournamentTable");
|
|
tournamentTableDiv = leaguePage.getHtmlElementById("tournamentTable");
|
|
|
tournamentTable = (HtmlTable) tournamentTableDiv.getFirstChild();
|
|
tournamentTable = (HtmlTable) tournamentTableDiv.getFirstChild();
|
|
|
- parseTournamentTable(sportId, countryId, leagueId, season, tournamentTable, gameDate, dateFormatter);
|
|
|
|
|
|
|
+ parseTournamentTable(sportId, countryId, leagueId, season, tournamentTable, gameDate,
|
|
|
|
|
+ dateFormatter);
|
|
|
currentParsePage = parsePage;
|
|
currentParsePage = parsePage;
|
|
|
}
|
|
}
|
|
|
// process new tournament table content
|
|
// process new tournament table content
|
|
@@ -222,9 +234,8 @@ public class OddsPortal implements ParserJoinedFunctions {
|
|
|
sqle.printStackTrace();
|
|
sqle.printStackTrace();
|
|
|
} catch (final ClassCastException cce) {
|
|
} catch (final ClassCastException cce) {
|
|
|
System.out.println("No pagination table");
|
|
System.out.println("No pagination table");
|
|
|
- // cce.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- finally {
|
|
|
|
|
|
|
+ // cce.printStackTrace();
|
|
|
|
|
+ } finally {
|
|
|
Mysql.getInstance().setParsingForLeague(leagueId, sportId, countryId, gameDate, currentParsePage, year);
|
|
Mysql.getInstance().setParsingForLeague(leagueId, sportId, countryId, gameDate, currentParsePage, year);
|
|
|
}
|
|
}
|
|
|
webClient.close();
|
|
webClient.close();
|
|
@@ -257,10 +268,9 @@ public class OddsPortal implements ParserJoinedFunctions {
|
|
|
homeTeam = participantsValue[0].trim();
|
|
homeTeam = participantsValue[0].trim();
|
|
|
awayTeam = participantsValue[1].trim();
|
|
awayTeam = participantsValue[1].trim();
|
|
|
|
|
|
|
|
-
|
|
|
|
|
final List<HtmlTableCell> cells = tr.getCells();
|
|
final List<HtmlTableCell> cells = tr.getCells();
|
|
|
for (final HtmlTableCell tc : cells) {
|
|
for (final HtmlTableCell tc : cells) {
|
|
|
- //Score
|
|
|
|
|
|
|
+ // Score
|
|
|
if (tc.getAttribute("class").contains("table-score")) {
|
|
if (tc.getAttribute("class").contains("table-score")) {
|
|
|
final String[] scoreValue = tc.getTextContent().split(":");
|
|
final String[] scoreValue = tc.getTextContent().split(":");
|
|
|
if (scoreValue[0].matches("\\D+")) {
|
|
if (scoreValue[0].matches("\\D+")) {
|
|
@@ -277,30 +287,34 @@ public class OddsPortal implements ParserJoinedFunctions {
|
|
|
if (tc.getTextContent().matches("[+-][0-9][0-9][0-9]")) {
|
|
if (tc.getTextContent().matches("[+-][0-9][0-9][0-9]")) {
|
|
|
if (odds1 == 0F) {
|
|
if (odds1 == 0F) {
|
|
|
odds1 = convertAmericanOddsToDecimal(Integer.valueOf(tc.getTextContent()));
|
|
odds1 = convertAmericanOddsToDecimal(Integer.valueOf(tc.getTextContent()));
|
|
|
- } else if (oddsX == 0F ) {
|
|
|
|
|
|
|
+ } else if (oddsX == 0F) {
|
|
|
oddsX = convertAmericanOddsToDecimal(Integer.valueOf(tc.getTextContent()));
|
|
oddsX = convertAmericanOddsToDecimal(Integer.valueOf(tc.getTextContent()));
|
|
|
- } else if (odds2 == 0F ) {
|
|
|
|
|
|
|
+ } else if (odds2 == 0F) {
|
|
|
odds2 = convertAmericanOddsToDecimal(Integer.valueOf(tc.getTextContent()));
|
|
odds2 = convertAmericanOddsToDecimal(Integer.valueOf(tc.getTextContent()));
|
|
|
}
|
|
}
|
|
|
} else if (tc.getTextContent().matches("[0-9].[0-9]+")) {
|
|
} else if (tc.getTextContent().matches("[0-9].[0-9]+")) {
|
|
|
if (odds1 == 0F) {
|
|
if (odds1 == 0F) {
|
|
|
odds1 = Float.valueOf(tc.getTextContent());
|
|
odds1 = Float.valueOf(tc.getTextContent());
|
|
|
- } else if (oddsX == 0F ) {
|
|
|
|
|
|
|
+ } else if (oddsX == 0F) {
|
|
|
oddsX = Float.valueOf(tc.getTextContent());
|
|
oddsX = Float.valueOf(tc.getTextContent());
|
|
|
- } else if (odds2 == 0F ) {
|
|
|
|
|
|
|
+ } else if (odds2 == 0F) {
|
|
|
odds2 = Float.valueOf(tc.getTextContent());
|
|
odds2 = Float.valueOf(tc.getTextContent());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (gameDate != null && homeTeam != null && awayTeam != null &&
|
|
|
|
|
- odds1 != 0 && oddsX != 0 && odds2 != 0 && !Strings.isNullOrEmpty(season)) { // All set.. update sql result table
|
|
|
|
|
- System.out.println("Adding game between " + homeTeam + " and " + awayTeam + " with score " + homeScore + "-" + awayScore);
|
|
|
|
|
- Mysql.getInstance().addResult("SoccerResults", gameDate, homeTeam, awayTeam, homeScore, awayScore, overtime, odds1, oddsX, odds2, countryId, season, leagueId, sportId);
|
|
|
|
|
|
|
+ if (gameDate != null && homeTeam != null && awayTeam != null && odds1 != 0 && oddsX != 0 && odds2 != 0
|
|
|
|
|
+ && !Strings.isNullOrEmpty(season)) { // All set.. update sql result table
|
|
|
|
|
+ System.out.println("Adding game between " + homeTeam + " and " + awayTeam + " with score "
|
|
|
|
|
+ + homeScore + "-" + awayScore);
|
|
|
|
|
+ Mysql.getInstance().addResult(new ResultDTO("SoccerResults", gameDate, homeTeam, awayTeam,
|
|
|
|
|
+ homeScore, awayScore, overtime, odds1, oddsX, odds2, countryId, season, leagueId, sportId));
|
|
|
} else {
|
|
} else {
|
|
|
- System.out.println(String.format("Not adding, missing somethind.. gameDate: %s, homeTeam %s, awayTeam %s, odds1 %s, oddsX %s, odds2 %s, "
|
|
|
|
|
- + "season %s", gameDate, homeTeam, awayTeam, odds1, oddsX, odds2, season));
|
|
|
|
|
|
|
+ System.out.println(String.format(
|
|
|
|
|
+ "Not adding, missing somethind.. gameDate: %s, homeTeam %s, awayTeam %s, odds1 %s, oddsX %s, odds2 %s, "
|
|
|
|
|
+ + "season %s",
|
|
|
|
|
+ gameDate, homeTeam, awayTeam, odds1, oddsX, odds2, season));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} else if (tr.getAttribute("class").contains("center nob-border")) { // Datum rader
|
|
} else if (tr.getAttribute("class").contains("center nob-border")) { // Datum rader
|