Ver Fonte

Oddsportal changes

Axel Nordh há 2 anos atrás
pai
commit
254bf89562
3 ficheiros alterados com 33 adições e 26 exclusões
  1. 10 9
      Odds/pom.xml
  2. 4 5
      Odds/src/main/Main.java
  3. 19 12
      Odds/src/parser/OddsPortal.java

+ 10 - 9
Odds/pom.xml

@@ -7,18 +7,19 @@
     <sourceDirectory>src</sourceDirectory>
     <plugins>
       <plugin>
-        <artifactId>maven-compiler-plugin</artifactId>
-        <version>3.8.1</version>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.12.1</version>
         <configuration>
-          <source>18</source>
-          <target>18</target>
+          <source>17</source>
+          <target>17</target>
         </configuration>
       </plugin>
       
       <plugin>
-    <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-shade-plugin</artifactId>
-        <version>3.4.1</version>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-shade-plugin</artifactId>
+          <version>3.5.1</version>
         <executions>
             <execution>
                 <phase>package</phase>
@@ -69,7 +70,7 @@
 -->
     </plugins>
   </build>
-<repositories>
+ <repositories>
   <repository>
     <id>nordhs-repo</id>
     <name>Nords Repo</name>
@@ -122,4 +123,4 @@
       </dependency>
   </dependencies>
   
-</project>
+</project>

+ 4 - 5
Odds/src/main/Main.java

@@ -1,12 +1,12 @@
 package main;
 
+import parser.OddsPortal;
+
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.time.LocalDateTime;
 
-import parser.OddsPortal;
-
 public class Main {
 
     public static void main(String[] args) {
@@ -51,13 +51,12 @@ public class Main {
 
         System.out.println("Getting One days ago matches");
         op.getMatches(LocalDateTime.now().plusDays(-1));
-        System.out.println("Getting Today days ago matches");
+        System.out.println("Getting Todays matches");
         op.getMatches(LocalDateTime.now().plusDays(0));
-         System.out.println("Getting Tomorrows matches");
+        System.out.println("Getting Tomorrows matches");
         op.getMatches(LocalDateTime.now().plusDays(1));
         System.out.println("Getting Next days matches");
         op.getMatches(LocalDateTime.now().plusDays(2));
-
     }
 
 }

+ 19 - 12
Odds/src/parser/OddsPortal.java

@@ -164,9 +164,9 @@ public class OddsPortal extends ParserBase implements ParserJoinedFunctions {
                     result.setLeagueId(leagueId);
                     result.setCountryId(countryId);
 
-                    firstResultsDiv = subDivs.get(2).findElement(By.xpath("./a"));
+                    firstResultsDiv = subDivs.get(2); //.findElement(By.xpath("./a"));
                 } else if (subDivs.size() == 1) {
-                    firstResultsDiv = subDivs.get(0).findElement(By.xpath("./a"));
+                    firstResultsDiv = subDivs.get(0); //.findElement(By.xpath("./a"));
                 } else {
                     System.out.println("No games found!");
                     continue;
@@ -220,7 +220,7 @@ public class OddsPortal extends ParserBase implements ParserJoinedFunctions {
 
     private void setGameDate(ResultDTO result, WebElement firstResultsDiv) {
         final List<Integer> time = new ArrayList<>();
-        String datePath = "./div/div/div//p";
+        String datePath = "./div/a/div/div//p";
         if (checkIfElementExists(firstResultsDiv, datePath)) {
             String timeText = firstResultsDiv.findElement(By.xpath(datePath)).getText();
             String[] timeSplit = timeText.split(":");
@@ -241,8 +241,8 @@ public class OddsPortal extends ParserBase implements ParserJoinedFunctions {
     }
 
     private void setOdds(ResultDTO result, WebElement firstResultsDiv) {
-        //List<WebElement> oddsDivs = firstResultsDiv.findElements(By.xpath("./div/div"));
-        List<WebElement> oddsDivs = firstResultsDiv.findElements(By.xpath("./parent::*/div"));
+        List<WebElement> oddsDivs = firstResultsDiv.findElements(By.xpath("./div/div"));
+        //List<WebElement> oddsDivs = firstResultsDiv.findElements(By.xpath("./parent::*/div"));
         try {
             result.setOdds1(Float.parseFloat(oddsDivs.get(0).getText()));
             result.setOddsX(Float.parseFloat(oddsDivs.get(1).getText()));
@@ -256,26 +256,33 @@ public class OddsPortal extends ParserBase implements ParserJoinedFunctions {
 
     }
 
+    /**
+     * Sets the scoring for the given result based on the provided WebElement.
+     *
+     * @param result the ResultDTO to set the scoring for
+     * @param firstResultsDiv the WebElement containing the scoring information
+     */
     private void setScoring(ResultDTO result, WebElement firstResultsDiv) {
-        // String resultPath = "./div/div/div[2]/div/div/div/div/div";
-        //String resultPath = "./div/div/div[1]/div[2]/div/div/div/div/div";
-        String resultPath = "./div/div[2]/div/div/div/div/div";
+        // XPath to locate the scoring information within the firstResultsDiv
+        String resultPath = "./div/a/div/div[2]/div/div/div/div/div";
 
+        // Check if the scoring element exists within the firstResultsDiv
         if (checkIfElementExists(firstResultsDiv, resultPath)) {
+            // Find the scoring divs based on the resultPath
             List<WebElement> scoringDivs = firstResultsDiv.findElements(By.xpath(resultPath));
             try {
+                // Set the home and away scores from the scoringDivs
                 result.setHomeScore(Integer.parseInt(scoringDivs.get(0).getText()));
                 result.setAwayScore(Integer.parseInt(scoringDivs.get(1).getText()));
             } catch (NumberFormatException e) {
-                // There is no scoring yet continue processing
+                // If the scoring information is not available, continue processing
             }
         }
-
     }
 
     private void setTeamsInfo(ResultDTO result, WebElement firstResultsDiv) {
-        String homeTeamName = firstResultsDiv.findElement(By.xpath(".//a[1]//p")).getText().trim();
-        String awayTeamName = firstResultsDiv.findElement(By.xpath(".//a[2]//p")).getText().trim();
+        String homeTeamName = firstResultsDiv.findElement(By.xpath(".//a[1]/div/div[2]//p")).getText().trim();
+        String awayTeamName = firstResultsDiv.findElement(By.xpath(".//a[1]/div/div[2]/div/div/a[2]//p")).getText().trim();
 
         result.setHomeTeam(homeTeamName);
         result.setAwayTeam(awayTeamName);