Ver Fonte

Getting Expect odds from JSON

Axel Nordh há 3 anos atrás
pai
commit
3ee0f4bd2f

+ 36 - 36
Odds/.classpath

@@ -1,36 +1,36 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
-		<attributes>
-			<attribute name="maven.pomderived" value="true"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-18">
-		<attributes>
-			<attribute name="maven.pomderived" value="true"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="src" path="target/generated-sources/annotations">
-		<attributes>
-			<attribute name="optional" value="true"/>
-			<attribute name="maven.pomderived" value="true"/>
-			<attribute name="ignore_optional_problems" value="true"/>
-			<attribute name="m2e-apt" value="true"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="src" output="target/classes" path="src">
-		<attributes>
-			<attribute name="optional" value="true"/>
-			<attribute name="maven.pomderived" value="true"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
-		<attributes>
-			<attribute name="optional" value="true"/>
-			<attribute name="maven.pomderived" value="true"/>
-			<attribute name="ignore_optional_problems" value="true"/>
-			<attribute name="m2e-apt" value="true"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="output" path="target/classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-18">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" path="target/generated-sources/annotations">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+			<attribute name="ignore_optional_problems" value="true"/>
+			<attribute name="m2e-apt" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" output="target/classes" path="src">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+			<attribute name="ignore_optional_problems" value="true"/>
+			<attribute name="m2e-apt" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

+ 6 - 2
Odds/pom.xml

@@ -51,7 +51,7 @@
     <dependency>
       <groupId>net.sourceforge.htmlunit</groupId>
       <artifactId>htmlunit</artifactId>
-      <version>2.64.0</version>
+      <version>2.66.0</version>
     </dependency>
     <dependency>
       <groupId>com.github.jbytecode</groupId>
@@ -68,6 +68,10 @@
         <artifactId>spring-boot-maven-plugin</artifactId>
         <version>2.7.1</version>
     </dependency>
-
+<dependency>
+    <groupId>com.fasterxml.jackson.core</groupId>
+    <artifactId>jackson-databind</artifactId>
+    <version>2.13.3</version>
+</dependency>
   </dependencies>
 </project>

+ 20 - 9
Odds/src/Main.java

@@ -2,25 +2,36 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 
+import parser.ExpektParser;
 import parser.OddsPortal;
 
 public class Main {
 
 	public static void main(String[] args) {
-		final OddsPortal op = new OddsPortal();
-		System.out.println("Getting Yesterdays matches");
-		op.getYesterdaysMatches();
-		System.out.println("Getting Todays Matches");
-		op.getTodaysMatches();
-		System.out.println("Getting tomorrows matches");
-		op.getTomorrowsMatches();
-
-		op.getNextDaysMatches();
 
+		//testExpektParser();
+		updateFromOddsportal();
 		// op.getHistoricMatches("soccer", "japan", "j2-league", "2020");
 		// callingRScript();
 	}
 
+	private static void testExpektParser() {
+		ExpektParser expektParser = new ExpektParser();
+
+	}
+
+	private static void updateFromOddsportal() {
+		final OddsPortal op = new OddsPortal();
+			System.out.println("Getting Yesterdays matches");
+			op.getYesterdaysMatches();
+			System.out.println("Getting Todays Matches");
+			op.getTodaysMatches();
+			System.out.println("Getting tomorrows matches");
+			op.getTomorrowsMatches();
+
+			op.getNextDaysMatches();
+	}
+
 	private static void callingRScript() throws IOException {
 		System.out.println(System.getProperty("user.dir"));
 		final String rPath = System.getProperty("user.dir") + "\\src\\RScript\\scorePrediction.R";

+ 90 - 0
Odds/src/parser/ExpektParser.java

@@ -0,0 +1,90 @@
+package parser;
+
+import java.io.IOException;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.time.LocalDateTime;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.sql.rowset.spi.SyncResolver;
+
+import org.apache.commons.io.IOUtils;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.gargoylesoftware.htmlunit.BrowserVersion;
+import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
+import com.gargoylesoftware.htmlunit.Page;
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.WebResponse;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+
+public class ExpektParser {
+    
+    public ExpektParser() {
+        getJSON();
+        //getSoccerMatches();
+    }
+
+    public static JsonNode get(URL url) throws Exception {
+        ObjectMapper mapper = new ObjectMapper();
+        return mapper.readTree(url);
+    }
+
+    // https://eu-offering.kambicdn.org/offering/v2018/expektse/listView/football.json?lang=sv_SE&market=SE
+
+private void getJSON() {
+    try {
+        URL url = new URL("https://eu-offering.kambicdn.org/offering/v2018/expektse/listView/football.json?lang=sv_SE&market=SE");
+        System.out.println("Getting url");
+        JsonNode node = get(url);
+        System.out.println("Got URL");
+        System.out.println(node.elements().next());
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
+}
+
+    private void getSoccerMatches() {
+        String url = "https://www.expekt.se/sv-se/sports#filter/football";
+
+        WebClient webClient = new WebClient();
+        webClient.getOptions().setUseInsecureSSL(true);
+        webClient.getOptions().setCssEnabled(false);
+        webClient.getOptions().setJavaScriptEnabled(false);
+        webClient.getOptions().setThrowExceptionOnScriptError(false);
+        Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF);
+
+        //webClient.waitForBackgroundJavaScript(20000);
+        try {
+            System.out.println("Starting to Get page with wait 20 seconds " + LocalDateTime.now());
+
+            webClient.waitForBackgroundJavaScript(3000);
+            HtmlPage page = webClient.getPage(url);  
+            
+            page = webClient.getPage(url);
+
+            System.out.println(page.asNormalizedText());
+
+            WebResponse webResponse = page.getWebResponse();
+            int i = 0;
+            // while (!webResponse.getContentAsString().contains("KambiBC-event-groups-list")){
+            //     webClient.waitForBackgroundJavaScript(500);
+            //     if (i++ < 50) {
+            //         System.out.println("Waiting");
+
+            //     }  else {
+            //         break;
+            //     }
+            // }
+            System.out.println("Done waiting " + LocalDateTime.now());
+
+            //System.out.println(webResponse.getContentAsString());
+        } catch (FailingHttpStatusCodeException | IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+}

+ 39 - 39
OddsJavaFx/.classpath

@@ -1,39 +1,39 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-	<classpathentry combineaccessrules="false" kind="src" path="/Odds"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-18">
-		<attributes>
-			<attribute name="maven.pomderived" value="true"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
-		<attributes>
-			<attribute name="maven.pomderived" value="true"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="con" path="org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JavaFx"/>
-	<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
-		<attributes>
-			<attribute name="optional" value="true"/>
-			<attribute name="maven.pomderived" value="true"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="src" path="target/generated-sources/annotations">
-		<attributes>
-			<attribute name="optional" value="true"/>
-			<attribute name="maven.pomderived" value="true"/>
-			<attribute name="ignore_optional_problems" value="true"/>
-			<attribute name="m2e-apt" value="true"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
-		<attributes>
-			<attribute name="optional" value="true"/>
-			<attribute name="maven.pomderived" value="true"/>
-			<attribute name="ignore_optional_problems" value="true"/>
-			<attribute name="m2e-apt" value="true"/>
-		</attributes>
-	</classpathentry>
-	<classpathentry kind="output" path="target/classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry combineaccessrules="false" kind="src" path="/Odds"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-18">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JavaFx"/>
+	<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" path="target/generated-sources/annotations">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+			<attribute name="ignore_optional_problems" value="true"/>
+			<attribute name="m2e-apt" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+			<attribute name="ignore_optional_problems" value="true"/>
+			<attribute name="m2e-apt" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

BIN
OddsJavaFx/src/lib/Odds-0.0.1-SNAPSHOT.jar