From d6fefd795f8bc1cdd56ed25f9fdbbe2267ee111e Mon Sep 17 00:00:00 2001 From: Michael Fross Date: Fri, 15 Jan 2021 09:24:33 -0600 Subject: [PATCH] Index provider changed their page - updated regex's --- pom.xml | 2 +- snap/snapcraft.yaml | 2 +- src/main/java/org/fross/quoter/Index.java | 4 +-- src/main/java/org/fross/quoter/Main.java | 31 ++++++++++------------- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 4507bf7..d9fd7ca 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.fross quoter - 2.3.2 + 2.3.3 jar quoter diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 5349fe2..9ad8448 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: quoter -version: '2.3.2' +version: '2.3.3' summary: Command line utility to pull stock and index quotes description: | Quote fetches stock quotes and index data from IEXCloud.IO. diff --git a/src/main/java/org/fross/quoter/Index.java b/src/main/java/org/fross/quoter/Index.java index bf52580..b7b76a0 100644 --- a/src/main/java/org/fross/quoter/Index.java +++ b/src/main/java/org/fross/quoter/Index.java @@ -74,8 +74,8 @@ protected static String[] getIndex(String idx) { searchPatterns[1] = "\"last\":\"(.*?)\""; searchPatterns[2] = "\"change\":\"(.*?)\""; searchPatterns[3] = "\"change_pct\":\"(.*?)\""; - searchPatterns[4] = "'year high'.*?\\>(.*?)\\<"; - searchPatterns[5] = "'year low'.*?\\>(.*?)\\<"; + searchPatterns[4] = "QuoteStrip-fiftyTwoWeekRange\"\\>(.*?)\\<"; + searchPatterns[5] = "QuoteStrip-fiftyTwoWeekRange.*? - .*?\\>(.*?)\\<"; retArray[0] = idx; for (int i = 1; i < searchPatterns.length; i++) { diff --git a/src/main/java/org/fross/quoter/Main.java b/src/main/java/org/fross/quoter/Main.java index f1c0afb..4a95e06 100644 --- a/src/main/java/org/fross/quoter/Main.java +++ b/src/main/java/org/fross/quoter/Main.java @@ -73,8 +73,7 @@ public static void main(String[] args) { Properties prop = new Properties(); prop.load(iStream); VERSION = prop.getProperty("Application.version"); - COPYRIGHT = "Copyright " + prop.getProperty("Application.inceptionYear") + "-" + org.fross.library.Date.getCurrentYear() - + " by Michael Fross"; + COPYRIGHT = "Copyright " + prop.getProperty("Application.inceptionYear") + "-" + org.fross.library.Date.getCurrentYear() + " by Michael Fross"; } catch (IOException ex) { Output.fatalError("Unable to read property file '" + PROPERTIES_FILE + "'", 3); } @@ -141,7 +140,7 @@ public static void main(String[] args) { Output.println(COPYRIGHT); System.exit(0); break; - + // Disable colorized output case 'z': Output.enableColor(false); @@ -334,11 +333,12 @@ public static void main(String[] args) { // Loop through the three indexes and display the results String[] indexList = { "DOW", "NASDAQ", "S&P" }; - try { - for (int i = 0; i < indexList.length; i++) { + for (int i = 0; i < indexList.length; i++) { + String[] outString = new String[6]; + String[] result = Index.getIndex(indexList[i]); + try { // Download the web page and return the results array Output.debugPrint("Getting Index data for: " + indexList[i]); - String[] result = Index.getIndex(indexList[i]); // Determine the color based on the change amount Ansi.Color outputColor = Ansi.Color.WHITE; @@ -347,21 +347,18 @@ public static void main(String[] args) { } // Format the Output - // Index Name - String[] outString = new String[6]; - // Symbol outString[0] = String.format("%-10s", result[0]); // Current - outString[1] = String.format("%,10.2f", Float.valueOf(result[1])); + outString[1] = String.format("%,10.2f", Float.valueOf(result[1].replace(",", ""))); // Change Amount - outString[2] = String.format("%+,10.2f", Float.valueOf(result[2])); + outString[2] = String.format("%+,10.2f", Float.valueOf(result[2].replace(",", ""))); // Change Percentage - outString[3] = String.format("%+,10.2f%%", Float.valueOf(result[3])); + outString[3] = String.format("%+,10.2f%%", Float.valueOf(result[3].replace("%", ""))); // 52Week High - outString[4] = String.format("%,14.2f", Float.valueOf(result[4])); + outString[4] = String.format("%,14.2f", Float.valueOf(result[4].replace(",", ""))); // 52Week Low - outString[5] = String.format("%,14.2f", Float.valueOf(result[5])); + outString[5] = String.format("%,14.2f", Float.valueOf(result[5].replace(",", ""))); // Display Index results to the screen for (int k = 0; k < outString.length; k++) { @@ -375,10 +372,10 @@ public static void main(String[] args) { if (exportFlag == true && exporter.canWrite()) { exporter.exportIndexes(result); } - } + } catch (Exception Ex) { + Output.printColorln(Ansi.Color.RED, outString[0] + ": No Data"); - } catch (Exception Ex) { - Output.printColor(Ansi.Color.RED, "No Data"); + } } // Display date of the data as pulled from iecloud.net. If no symbols were provided and