Skip to content

Commit

Permalink
Added company name to top of trend chart
Browse files Browse the repository at this point in the history
  • Loading branch information
frossm committed Jul 11, 2023
1 parent 0111899 commit 5934f0c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 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.10</version>
<version>5.0.11</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.10'
version: '5.0.11'
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
2 changes: 1 addition & 1 deletion src/main/java/org/fross/quoter/HistoricalQuotes.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void displayTrend(String symb) {
// Display the symbol informational header
Output.printColorln(Ansi.Color.WHITE,
"\n\n+--" + NUM_DAYS_IN_TREND + " Day Trend" + "-".repeat(graphWidth - String.valueOf(NUM_DAYS_IN_TREND).length() + 8) + "+");
Output.printColorln(Ansi.Color.YELLOW, symb.toUpperCase());
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));
Output.printColorln(Ansi.Color.YELLOW, NUM_DAYS_IN_TREND + " Day High: " + String.format("%,.2f", lv));
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/fross/quoter/Symbol.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ private void getSymbolData(String symb) {
xPath = "/html/body/div[3]/div[2]/div[3]/div/div[1]/span/bg-quote";
result = queryPageItem(htmlPage, xPath);
symbolData.put("timeStamp", result.replaceAll("[,%]", "").trim());

// Full Name of Company
xPath = "/html/body/div[3]/div[2]/div[2]/div/div[2]/h1";
result = queryPageItem(htmlPage, xPath);
symbolData.put("fullname", result.trim());

} else {
// Market is OPEN
Expand Down Expand Up @@ -272,6 +277,11 @@ private void getSymbolData(String symb) {
xPath = "/html/body/div[3]/div[2]/div[3]/div/div[1]/span/bg-quote";
result = queryPageItem(htmlPage, xPath);
symbolData.put("timeStamp", result.replaceAll("[,%]", "").trim());

// Full Name of Company
xPath = "/html/body/div[3]/div[2]/div[2]/div/div[2]/h1";
result = queryPageItem(htmlPage, xPath);
symbolData.put("fullname", result.trim());
}

// If we are in debug mode, display the values of the symbol
Expand Down
11 changes: 7 additions & 4 deletions src/test/java/org/fross/quoter/SymbolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
***************************************************************************************************************/
package org.fross.quoter;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;

Expand All @@ -35,10 +36,11 @@ class SymbolTest {

// Look through a list of symbols and ensure all the right fields are present
@Test
void test() {
void testFields() {
String[] testSymbols = { "IBM", "TSLA", "GOOG" };
String[] symbolFullName = { "International Business Machines Corp.", "Tesla Inc.", "Alphabet Inc. Cl C" };
String[] testFields = { "symbol", "latestPrice", "change", "changePercent", "dayHigh", "dayLow", "ytdChangePercent", "oneYearChangePercent",
"timeStamp", "week52High", "week52Low", "status" };
"timeStamp", "week52High", "week52Low", "fullname", "status" };

// Loop through each symbol we are testing
for (int i = 0; i < testSymbols.length; i++) {
Expand All @@ -53,8 +55,9 @@ void test() {
fail("'" + testFields[i] + "' does not exist");
}
}
}

// Since the names shouldn't change, lets test a few of the fullname fields
assertEquals(symb.get("fullname"), symbolFullName[i]);
}
}

}

0 comments on commit 5934f0c

Please sign in to comment.