Skip to content

Commit

Permalink
Some simple code cleanup - no functional changes
Browse files Browse the repository at this point in the history
  • Loading branch information
frossm committed Aug 10, 2023
1 parent bdcfecc commit 99bfd61
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 113 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

<groupId>org.fross</groupId>
<artifactId>quoter</artifactId>
<version>5.0.20</version>
<version>5.0.21</version>
<packaging>jar</packaging>

<name>quoter</name>
<description>Simple console based program to display stock quotes and index data</description>
<description>A simple console based program to display stock quotes, US core index data, and historical trending</description>
<url>https://fross.org</url>

<developers>
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.20'
version: '5.0.21'
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
20 changes: 10 additions & 10 deletions src/main/java/org/fross/quoter/FileExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public FileExporter(String fileName) {

// Create the FileWriter object for writing to the export file
try {
exportFileFW = new FileWriter(this.exportFile);
this.exportFileFW = new FileWriter(this.exportFile);
} catch (IOException ex) {
Output.printColorln(Ansi.Color.RED, "Error writing to export file '" + fileName + "'\n" + ex.getMessage());
}
Expand All @@ -71,7 +71,7 @@ public FileExporter(String fileName) {
*/
public boolean canWrite() {
try {
return exportFile.canWrite();
return this.exportFile.canWrite();
} catch (Exception ex) {
return false;
}
Expand All @@ -90,9 +90,9 @@ public boolean exportSecurities(Symbol symbolObj) {
if (this.exportSymbolHeaderWritten == false) {
for (String i : fields) {
if (!i.matches("[Ss]tatus"))
exportFileFW.append(i + ",");
this.exportFileFW.append(i + ",");
}
exportFileFW.append("\n");
this.exportFileFW.append("\n");
this.exportSymbolHeaderWritten = true;
}

Expand All @@ -101,9 +101,9 @@ public boolean exportSecurities(Symbol symbolObj) {
// If the data has a ',' in it remove it
String item = symbolObj.get(i).replaceAll(",", "");
if (!symbolObj.get(i).matches("[Oo][Kk]"))
exportFileFW.append(item + ",");
this.exportFileFW.append(item + ",");
}
exportFileFW.append("\n");
this.exportFileFW.append("\n");

} catch (IOException ex) {
Output.printColorln(Ansi.Color.RED, "Error writing data to the export file: " + ex.getMessage());
Expand All @@ -117,22 +117,22 @@ public boolean exportSecurities(Symbol symbolObj) {
*/
public void exportIndexes(Index indexObj) {
try {
exportFileFW.append("\n");
this.exportFileFW.append("\n");
// Dump the header information to the export file
List<String> fields = indexObj.getAllFieldNames();
if (this.exportIndexHeaderWritten == false) {
for (String i : fields) {
if (!i.matches("[Ss]tatus"))
exportFileFW.append(i + ",");
this.exportFileFW.append(i + ",");
}
exportFileFW.append("\n");
this.exportFileFW.append("\n");
this.exportIndexHeaderWritten = true;
}

// Dump the index data
for (String key : indexObj.getAllFieldNames()) {
if (!indexObj.get(key).matches("[Oo][Kk]"))
exportFileFW.append("\"" + indexObj.get(key) + "\"" + ",");
this.exportFileFW.append("\"" + indexObj.get(key) + "\"" + ",");
}

} catch (IOException ex) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/fross/quoter/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public class Help {
static final int HEADERWIDTH = 72;

/**
* Display(): Prints help in color using the JCDP library in the output module.
* Display(): Prints help in color using the JCDP library in the output module
*/
public static void Display() {
Output.printColorln(Ansi.Color.CYAN, "\n+" + "-".repeat(HEADERWIDTH - 2) + "+");
Output.printColorln(Ansi.Color.CYAN, "+" + Format.CenterText(HEADERWIDTH - 2, "Quoter v" + Main.VERSION) + "+");
Output.printColorln(Ansi.Color.CYAN, "+" + Format.CenterText(HEADERWIDTH - 2, Main.COPYRIGHT) + "+");
Output.printColorln(Ansi.Color.CYAN, "+" + "-".repeat(HEADERWIDTH - 2) + "+");
Output.printColorln(Ansi.Color.CYAN, Format.CenterText(HEADERWIDTH - 2, "Quoter displays stock quotes & US index data, and more"));
Output.printColorln(Ansi.Color.CYAN, Format.CenterText(HEADERWIDTH - 2, "Quoter displays stock quotes, US index data, and trends"));
Output.printColorln(Ansi.Color.CYAN, Format.CenterText(HEADERWIDTH - 2, "Hompage: https://github.com/frossm/quoter") + "\n");

Output.printColorln(Ansi.Color.YELLOW, "Command Line Options");
Expand All @@ -72,7 +72,7 @@ public static void Display() {

Output.printColorln(Ansi.Color.YELLOW, "\nMisc:");
Output.printColorln(Ansi.Color.WHITE, " -D Start in debug mode and display details for developers");
Output.printColorln(Ansi.Color.WHITE, " -v Display program version and lastest GitHub release and exit");
Output.printColorln(Ansi.Color.WHITE, " -v Display program version and the lastest release on GitHub");
Output.printColorln(Ansi.Color.WHITE, " -? | -h Display this help information");

Output.printColorln(Ansi.Color.YELLOW, "\nNotes:");
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/fross/quoter/HistoricalQuotes.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ public void displayTrend(String symb) {
Output.debugPrintln("Slots per Cost Unit: " + slotsPerCostUnit);

// Display the symbol informational header
Output.printColorln(Ansi.Color.WHITE, "\n\n+--" + String.format("%02d", NUM_DAYS_IN_TREND) + " Day Trend"
+ "-".repeat(graphWidth - 2) + "+");
Output.printColorln(Ansi.Color.WHITE, "\n\n+--" + String.format("%02d", NUM_DAYS_IN_TREND) + " Day Trend" + "-".repeat(graphWidth - 2) + "+");
Output.printColorln(Ansi.Color.YELLOW, symb.toUpperCase() + " : " + symbolData.get("fullname"));
Output.printColorln(Ansi.Color.YELLOW, "Current Price: " + symbolData.get("latestPrice"));
Output.printColorln(Ansi.Color.YELLOW, NUM_DAYS_IN_TREND + " Day Low: " + String.format("%,.2f", sv));
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/org/fross/quoter/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Index(String idx) {
public boolean queryMarketOpen() {
return marketOpen;
}

/**
* queryPageItem():Find the specific value in the provided doc with the xPath given
*
Expand Down Expand Up @@ -169,7 +169,7 @@ private void getIndex(String idx) {
this.indexData.put("status", "ok");

// Determine if the market is open or closed
if (Symbol.queryPageItem(htmlPage, xPathLookup.lookupIndexOpen("marketStatus")).toLowerCase().contains("closed") == true) {
if (Symbol.queryPageItem(htmlPage, this.xPathLookup.lookupIndexOpen("marketStatus")).toLowerCase().contains("closed") == true) {
marketOpen = false;
} else {
marketOpen = true;
Expand All @@ -182,22 +182,22 @@ private void getIndex(String idx) {

// Current Price
String key = "latestPrice";
String result = queryPageItem(htmlPage, xPathLookup.lookupIndexClosed(key));
String result = queryPageItem(htmlPage, this.xPathLookup.lookupIndexClosed(key));
indexData.put(key, result.replaceAll("[,%]", "").trim());

// Change
key = "change";
result = queryPageItem(htmlPage, xPathLookup.lookupIndexClosed(key));
result = queryPageItem(htmlPage, this.xPathLookup.lookupIndexClosed(key));
indexData.put(key, result.replaceAll("[,%]", "").trim());

// Change Percent
key = "changePercent";
result = queryPageItem(htmlPage, xPathLookup.lookupIndexClosed(key));
result = queryPageItem(htmlPage, this.xPathLookup.lookupIndexClosed(key));
indexData.put(key, result.replaceAll("[,%]", "").trim());

// 52 Week Range
key = "52weekRange";
result = queryPageItem(htmlPage, xPathLookup.lookupIndexClosed(key));
result = queryPageItem(htmlPage, this.xPathLookup.lookupIndexClosed(key));

String w52Low = result.split(" - ")[0];
String w52High = result.split(" - ")[1];
Expand All @@ -207,17 +207,17 @@ private void getIndex(String idx) {

// Year to Date Change Percent
key = "ytdChangePercent";
result = queryPageItem(htmlPage, xPathLookup.lookupIndexClosed(key));
result = queryPageItem(htmlPage, this.xPathLookup.lookupIndexClosed(key));
indexData.put(key, result.replaceAll("[,%]", "").trim());

// One Year Change Percent
key = "oneYearChangePercent";
result = queryPageItem(htmlPage, xPathLookup.lookupIndexClosed(key));
result = queryPageItem(htmlPage, this.xPathLookup.lookupIndexClosed(key));
indexData.put(key, result.replaceAll("[,%]", "").trim());

// TimeStamp
key = "timeStamp";
result = queryPageItem(htmlPage, xPathLookup.lookupIndexClosed(key));
result = queryPageItem(htmlPage, this.xPathLookup.lookupIndexClosed(key));
indexData.put(key, result.replaceAll("[,%]", "").trim());

} else {
Expand All @@ -226,22 +226,22 @@ private void getIndex(String idx) {

// Current Price
String key = "latestPrice";
String result = queryPageItem(htmlPage, xPathLookup.lookupIndexOpen(key));
String result = queryPageItem(htmlPage, this.xPathLookup.lookupIndexOpen(key));
indexData.put(key, result.replaceAll("[,%]", "").trim());

// Change
key = "change";
result = queryPageItem(htmlPage, xPathLookup.lookupIndexOpen(key));
result = queryPageItem(htmlPage, this.xPathLookup.lookupIndexOpen(key));
indexData.put("change", result.replaceAll("[,%]", "").trim());

// Change Percent
key = "changePercent";
result = queryPageItem(htmlPage, xPathLookup.lookupIndexOpen(key));
result = queryPageItem(htmlPage, this.xPathLookup.lookupIndexOpen(key));
indexData.put(key, result.replaceAll("[,%]", "").trim());

// 52 Week Range
key = "52weekRange";
result = queryPageItem(htmlPage, xPathLookup.lookupIndexOpen(key));
result = queryPageItem(htmlPage, this.xPathLookup.lookupIndexOpen(key));

String w52Low = result.split(" - ")[0];
String w52High = result.split(" - ")[1];
Expand All @@ -251,17 +251,17 @@ private void getIndex(String idx) {

// Year to Date
key = "ytdChangePercent";
result = queryPageItem(htmlPage, xPathLookup.lookupIndexOpen(key));
result = queryPageItem(htmlPage, this.xPathLookup.lookupIndexOpen(key));
indexData.put(key, result.replaceAll("[,%]", "").trim());

// One Year Change Percent
key = "oneYearChangePercent";
result = queryPageItem(htmlPage, xPathLookup.lookupIndexOpen(key));
result = queryPageItem(htmlPage, this.xPathLookup.lookupIndexOpen(key));
indexData.put(key, result.replaceAll("[,%]", "").trim());

// TimeStamp
key = "timeStamp";
result = queryPageItem(htmlPage, xPathLookup.lookupIndexOpen(key));
result = queryPageItem(htmlPage, this.xPathLookup.lookupIndexOpen(key));
indexData.put(key, result.replaceAll("[,%]", "").trim());

}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/fross/quoter/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* SOFTWARE.
*
***************************************************************************************************************/

package org.fross.quoter;

import static org.fusesource.jansi.Ansi.ansi;
Expand Down
34 changes: 30 additions & 4 deletions src/main/java/org/fross/quoter/QuoteConsoleOutput.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
/**************************************************************************************************************
* Quoter.jar
*
* Quoter is a command line program that display stock quotes and index data.
*
* Copyright (c) 2019-2022 Michael Fross
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
***************************************************************************************************************/
package org.fross.quoter;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -238,11 +264,11 @@ public void displayOutput(FileExporter exporter) {
}

// Display the open/closed status of the market
Output.printColor(Ansi.Color.CYAN, "\nThe US markets are currently: ");
Output.printColor(Ansi.Color.WHITE, "\nThe US markets are currently: ");
if (new Index("DOW").queryMarketOpen() == true) {
Output.printColorln(Ansi.Color.YELLOW, "~ OPEN ~");
Output.printColorln(Ansi.Color.YELLOW, "-= OPEN =-");
} else {
Output.printColorln(Ansi.Color.YELLOW, "~ CLOSED ~");
Output.printColorln(Ansi.Color.YELLOW, "-= CLOSED =-");
}

// Convert to local time & time zone
Expand Down Expand Up @@ -281,7 +307,7 @@ public void displayOutput(FileExporter exporter) {
timeStamp = timeStamp.replaceAll("AM", "am");

// Display the time stamp
Output.printColorln(Ansi.Color.CYAN, "Data as of " + timeStamp + ". Quotes are delayed.");
Output.printColorln(Ansi.Color.WHITE, "Data as of " + timeStamp + ". Quotes are delayed.");

// Display trending data if -t was provided and there is at least one valid symbol
if (cli.clTrend == true) {
Expand Down
Loading

0 comments on commit 99bfd61

Please sign in to comment.