Skip to content

Commit

Permalink
Export is now working again
Browse files Browse the repository at this point in the history
  • Loading branch information
frossm committed Jun 29, 2023
1 parent cfb055f commit 33de0fe
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 59 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.fross</groupId>
<artifactId>quoter</artifactId>
<version>5.0.4</version>
<version>5.0.5</version>
<packaging>jar</packaging>

<name>quoter</name>
Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 19 additions & 11 deletions src/main/java/org/fross/quoter/FileExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> fields = symbolData.getAllFieldNames();
List<String> 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;
Expand All @@ -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");

Expand All @@ -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<String> 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());
Expand Down
53 changes: 7 additions & 46 deletions src/main/java/org/fross/quoter/QuoteConsoleOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

}
Expand Down Expand Up @@ -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");
}
Expand All @@ -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()) {
Expand Down

0 comments on commit 33de0fe

Please sign in to comment.