From a53b81e084a4faa13970fac598717ac2098da9d9 Mon Sep 17 00:00:00 2001 From: Gilberto Caetano de Andrade Date: Wed, 14 Jun 2023 15:01:44 -0300 Subject: [PATCH 1/6] append the crumb to the URL --- .../java/yahoofinance/quotes/query1v7/QuotesRequest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/yahoofinance/quotes/query1v7/QuotesRequest.java b/src/main/java/yahoofinance/quotes/query1v7/QuotesRequest.java index 5daf346c..b429229c 100644 --- a/src/main/java/yahoofinance/quotes/query1v7/QuotesRequest.java +++ b/src/main/java/yahoofinance/quotes/query1v7/QuotesRequest.java @@ -16,6 +16,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import yahoofinance.histquotes2.CrumbManager; /** * @@ -61,7 +62,9 @@ public List getResult() throws IOException { params.put("symbols", this.symbols); String url = YahooFinance.QUOTES_QUERY1V7_BASE_URL + "?" + Utils.getURLParameters(params); - + if (!CrumbManager.getCrumb().isEmpty()) { + url = url + "&crumb=" + CrumbManager.getCrumb(); + } // Get JSON from Yahoo log.info("Sending request: " + url); From cefd6c7f6c272041eb39905b0fee04ba8e46af10 Mon Sep 17 00:00:00 2001 From: Gilberto Caetano de Andrade Date: Tue, 1 Aug 2023 14:03:44 -0300 Subject: [PATCH 2/6] add a user-agent header to the getcrumb request --- src/main/java/yahoofinance/histquotes2/CrumbManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/yahoofinance/histquotes2/CrumbManager.java b/src/main/java/yahoofinance/histquotes2/CrumbManager.java index 1ca30a11..afcff2cd 100644 --- a/src/main/java/yahoofinance/histquotes2/CrumbManager.java +++ b/src/main/java/yahoofinance/histquotes2/CrumbManager.java @@ -162,6 +162,7 @@ private static void setCrumb() throws IOException { Map requestProperties = new HashMap(); requestProperties.put("Cookie", cookie); + requestProperties.put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.2 Safari/605.1.15"); URLConnection crumbConnection = redirectableCrumbRequest.openConnection(requestProperties); InputStreamReader is = new InputStreamReader(crumbConnection.getInputStream()); From 5d2fbdfa088366213f778be13d8c83676d055ef4 Mon Sep 17 00:00:00 2001 From: Gilberto Caetano de Andrade Date: Thu, 25 Apr 2024 08:43:20 -0300 Subject: [PATCH 3/6] Fix Javadoc search path for Java 9+ --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index ebf3e8f7..62fa1659 100644 --- a/pom.xml +++ b/pom.xml @@ -113,7 +113,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.9.1 + 3.3.0 attach-javadocs @@ -274,4 +274,4 @@ - \ No newline at end of file + From 54914e234f32240827aa0cc0f8a382041843e809 Mon Sep 17 00:00:00 2001 From: Gilberto Caetano de Andrade Date: Thu, 25 Apr 2024 08:43:36 -0300 Subject: [PATCH 4/6] Change B=.* in line 56 to A1S=.* --- src/main/java/yahoofinance/histquotes2/CrumbManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/yahoofinance/histquotes2/CrumbManager.java b/src/main/java/yahoofinance/histquotes2/CrumbManager.java index afcff2cd..2643c4b5 100644 --- a/src/main/java/yahoofinance/histquotes2/CrumbManager.java +++ b/src/main/java/yahoofinance/histquotes2/CrumbManager.java @@ -53,7 +53,7 @@ private static void setCookie() throws IOException { if("Set-Cookie".equalsIgnoreCase(headerKey)) { for(String cookieField : connection.getHeaderFields().get(headerKey)) { for(String cookieValue : cookieField.split(";")) { - if(cookieValue.matches("B=.*")) { + if(cookieValue.matches("A1S=.*")) { cookie = cookieValue; log.debug("Set cookie from http request: {}", cookie); return; From a73384deed5857e90ad07ea4797d89cbda6222f3 Mon Sep 17 00:00:00 2001 From: Gilberto Caetano de Andrade Date: Wed, 19 Jun 2024 09:51:46 -0300 Subject: [PATCH 5/6] fix 503 error on setCookie() --- src/main/java/yahoofinance/histquotes2/CrumbManager.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/yahoofinance/histquotes2/CrumbManager.java b/src/main/java/yahoofinance/histquotes2/CrumbManager.java index 2643c4b5..a3989748 100644 --- a/src/main/java/yahoofinance/histquotes2/CrumbManager.java +++ b/src/main/java/yahoofinance/histquotes2/CrumbManager.java @@ -46,8 +46,11 @@ private static void setCookie() throws IOException { redirectableRequest.setConnectTimeout(YahooFinance.CONNECTION_TIMEOUT); redirectableRequest.setReadTimeout(YahooFinance.CONNECTION_TIMEOUT); + Map requestProperties = new HashMap(); + requestProperties.put("Cookie", cookie); + requestProperties.put("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.2 Safari/605.1.15"); - URLConnection connection = redirectableRequest.openConnection(); + URLConnection connection = redirectableRequest.openConnection(requestProperties); for(String headerKey : connection.getHeaderFields().keySet()) { if("Set-Cookie".equalsIgnoreCase(headerKey)) { From b758af7f19197816a1d4cc12a620454f0b76bf7c Mon Sep 17 00:00:00 2001 From: Gilberto Caetano de Andrade Date: Mon, 26 Aug 2024 15:36:22 -0300 Subject: [PATCH 6/6] change to maven.compiler.release and sets the javac to 11 add simply tests to CrumbManager and QuoteRequestTest --- .gitignore | 1 + pom.xml | 36 +++++++++++++++++-- .../java/yahoofinance/CrumbManagerTest.java | 19 ++++++++++ .../java/yahoofinance/QuoteRequestTest.java | 19 ++++++++++ 4 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 src/test/java/yahoofinance/CrumbManagerTest.java create mode 100644 src/test/java/yahoofinance/QuoteRequestTest.java diff --git a/.gitignore b/.gitignore index 3fb2be90..0b7eee47 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ .idea /*.iml /classes/ +/.java-version diff --git a/pom.xml b/pom.xml index 62fa1659..6b5b7350 100644 --- a/pom.xml +++ b/pom.xml @@ -41,8 +41,7 @@ UTF-8 - 1.8 - 1.8 + 11 @@ -123,7 +122,38 @@ - + + org.apache.maven.plugins + maven-clean-plugin + 3.3.2 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + ${maven.compiler.release} + true + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.2 + + false + false + + + + org.apache.maven.wagon diff --git a/src/test/java/yahoofinance/CrumbManagerTest.java b/src/test/java/yahoofinance/CrumbManagerTest.java new file mode 100644 index 00000000..6f5deae7 --- /dev/null +++ b/src/test/java/yahoofinance/CrumbManagerTest.java @@ -0,0 +1,19 @@ +package yahoofinance; + +import static org.junit.Assert.assertNotNull; +import org.junit.Test; +import java.io.IOException; +import yahoofinance.histquotes2.CrumbManager; + +/** + * + * @author gilberto.andrade + */ +public class CrumbManagerTest { + + @Test + public void getCrumbTest() throws IOException { + assertNotNull(CrumbManager.getCrumb()); + } + +} \ No newline at end of file diff --git a/src/test/java/yahoofinance/QuoteRequestTest.java b/src/test/java/yahoofinance/QuoteRequestTest.java new file mode 100644 index 00000000..56177831 --- /dev/null +++ b/src/test/java/yahoofinance/QuoteRequestTest.java @@ -0,0 +1,19 @@ +package yahoofinance; + +import java.io.IOException; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author gilberto.andrade + */ +public class QuoteRequestTest { + + @Test + public void getQuoteTest() throws IOException { + Stock stock = YahooFinance.get("INTC"); + assertEquals(stock.getStats().getSymbol(), "INTC"); + + } +} \ No newline at end of file