From 33de0fe4383a1589dd42df0ad77bb162ad9b485a Mon Sep 17 00:00:00 2001 From: Michael Fross Date: Wed, 28 Jun 2023 19:09:14 -0500 Subject: [PATCH] Export is now working again --- pom.xml | 2 +- snap/snapcraft.yaml | 2 +- .../java/org/fross/quoter/FileExporter.java | 30 +++++++---- .../org/fross/quoter/QuoteConsoleOutput.java | 53 +++---------------- 4 files changed, 28 insertions(+), 59 deletions(-) diff --git a/pom.xml b/pom.xml index ae0c8cd..2b47db3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.fross quoter - 5.0.4 + 5.0.5 jar quoter diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 2ea30ae..87dbf32 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: quoter -version: '5.0.4' +version: '5.0.5' summary: Command line utility to pull stock and index quotes description: | Quoter fetches online stock quotes and index data for easy display on diff --git a/src/main/java/org/fross/quoter/FileExporter.java b/src/main/java/org/fross/quoter/FileExporter.java index 44addbb..1c963d6 100644 --- a/src/main/java/org/fross/quoter/FileExporter.java +++ b/src/main/java/org/fross/quoter/FileExporter.java @@ -80,16 +80,17 @@ public boolean canWrite() { /** * exportSecurities(): Dump the security symbol data to the export file * - * @param symbolData + * @param symbolObj * @return */ - public boolean exportSecurities(Symbol symbolData) { + public boolean exportSecurities(Symbol symbolObj) { try { // Export the header row - List fields = symbolData.getAllFieldNames(); + List fields = symbolObj.getAllFieldNames(); if (this.exportSymbolHeaderWritten == false) { for (String i : fields) { - exportFileFW.append(i + ","); + if (!i.matches("[Ss]tatus")) + exportFileFW.append(i + ","); } exportFileFW.append("\n"); this.exportSymbolHeaderWritten = true; @@ -98,8 +99,9 @@ public boolean exportSecurities(Symbol symbolData) { // Export the symbol data for (String i : fields) { // If the data has a ',' in it remove it - String item = symbolData.get(i).replaceAll(",", ""); - exportFileFW.append(item + ","); + String item = symbolObj.get(i).replaceAll(",", ""); + if (!symbolObj.get(i).matches("[Oo][Kk]")) + exportFileFW.append(item + ","); } exportFileFW.append("\n"); @@ -113,19 +115,25 @@ public boolean exportSecurities(Symbol symbolData) { /** * exportIndexes(): Dump the index data to the export file */ - public void exportIndexes(String[] indexData) { + public void exportIndexes(Index indexObj) { try { + exportFileFW.append("\n"); // Dump the header information to the export file + List fields = indexObj.getAllFieldNames(); if (this.exportIndexHeaderWritten == false) { - exportFileFW.append("\nSymbol,Current,Chng,Chng%,52WeekHigh,52WeekLow\n"); + for (String i : fields) { + if (!i.matches("[Ss]tatus")) + exportFileFW.append(i + ","); + } + exportFileFW.append("\n"); this.exportIndexHeaderWritten = true; } // Dump the index data - for (int k = 0; k < indexData.length; k++) { - exportFileFW.append("\"" + indexData[k] + "\"" + ","); + for (String key : indexObj.getAllFieldNames()) { + if (!indexObj.get(key).matches("[Oo][Kk]")) + exportFileFW.append("\"" + indexObj.get(key) + "\"" + ","); } - exportFileFW.append("\n"); } catch (IOException ex) { Output.printColorln(Ansi.Color.RED, "Error writing to export file: " + ex.getMessage()); diff --git a/src/main/java/org/fross/quoter/QuoteConsoleOutput.java b/src/main/java/org/fross/quoter/QuoteConsoleOutput.java index a3c96fe..fec3a6b 100644 --- a/src/main/java/org/fross/quoter/QuoteConsoleOutput.java +++ b/src/main/java/org/fross/quoter/QuoteConsoleOutput.java @@ -20,7 +20,7 @@ public QuoteConsoleOutput(final CommandLineParser cli) { * @param exporter */ public void invokeSymbolOutput(FileExporter exporter) { - // Store the timestamp + // Store the time stamp String timeStamp = ""; // Display the header @@ -145,9 +145,9 @@ public void invokeSymbolOutput(FileExporter exporter) { timeStamp = symbolObj.get("timeStamp"); // If export is chosen, dump this security's data to the export file -// if (cli.clExport.isEmpty() == false && exporter.canWrite()) { -// exporter.exportSecurities(symbolData); -// } + if (cli.clExport.isEmpty() == false && exporter.canWrite()) { + exporter.exportSecurities(symbolObj); + } } } @@ -214,9 +214,9 @@ public void invokeSymbolOutput(FileExporter exporter) { Output.println(""); // If export is chosen, dump this index's data to the export file -// if (cli.clExport.isEmpty() == false && exporter.canWrite()) { -// exporter.exportIndexes(result); -// } + if (cli.clExport.isEmpty() == false && exporter.canWrite()) { + exporter.exportIndexes(indexObj); + } } catch (Exception ex) { indexObj.put("status", "error"); } @@ -239,45 +239,6 @@ public void invokeSymbolOutput(FileExporter exporter) { Output.printColorln(Ansi.Color.CYAN, "Data as of " + timeStamp + " Eastern. Quotes are delayed."); - // Display detailed stock information if selected with the -d switch -// if (cli.clDetailedOutput && !cli.symbolList.isEmpty()) { -// final int HEADERWIDTH = 80; -// String[] companyFields = { "symbol", "companyName", "exchange", "industry", "website", "description", "CEO", "securityName", "issueType", "sector", -// "primarySicCode", "employees", "address", "address2", "city", "state", "zip", "country", "phone" }; -// -// String[] symbolFields = { "open", "openTime", "close", "closeTime", "high", "highTime", "low", "lowTime", "latestPrice", "latestVolume", -// "previousClose", "previousVolume", "change", "changePercent", "agTotalVolume", "marketCap", "peRatio", "week52High", "week52Low" }; -// -// Output.printColorln(Ansi.Color.WHITE, "\nDetailed Security Information:"); -// -// // Display detail of each symbol provided on command line -// for (String symb : cli.symbolList) { -// // Query company data -// IEXCloudAPICall companyDetail = new IEXCloudAPICall(Main.IEXCloudBaseURL + "/stable/stock/" + symb + "/company", IEXCloudToken); -// -// // Query symbol data -// Symbol symbolDetail = new Symbol(symb, IEXCloudToken); -// -// // Display Header -// Output.printColorln(Ansi.Color.CYAN, "-".repeat(HEADERWIDTH)); -// Output.printColorln(Ansi.Color.YELLOW, symb.toUpperCase() + " / " + companyDetail.get("companyName")); -// Output.printColorln(Ansi.Color.CYAN, "-".repeat(HEADERWIDTH)); -// -// // Display company information -// for (String field : companyFields) { -// Output.printColor(Ansi.Color.WHITE, " " + String.format("%-16s", Format.Capitalize(field) + ":") + " "); -// Output.printColorln(Ansi.Color.CYAN, " " + companyDetail.get(field)); -// } -// Output.println(""); -// -// // Loop through each detailed field and display it -// for (String field : symbolFields) { -// Output.printColorln(Ansi.Color.WHITE, " " + String.format("%-16s", Format.Capitalize(field) + ":") + " " + symbolDetail.get(field)); -// } -// Output.println(""); -// } -// } - // Display trending data if -t was provided and there is at least one valid symbol if (cli.clTrend == true) { if (!cli.symbolList.isEmpty()) {