Skip to content

Commit

Permalink
Added saved symbols to preferences. -s, -r, -i switches.
Browse files Browse the repository at this point in the history
  • Loading branch information
frossm committed Dec 11, 2020
1 parent 1fca3bc commit 27ed08f
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 41 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,27 @@ Note that if Quoter has been installed via a snap, `quoter -c` is all that is ne

## Program Options

#### Configuration
|Option|Description|
|------|-----------|
|-D | Start in Debug Mode which will display additional debugging data. Normally not used|
|-c | Configure the [IEXCloud.IO](https://iexcloud.io) API key|
|-k | Display the configured IEX secret API key and exit|
|-s | Save the securities provided into the preferences system to be executed each time Quoter is run. If a `-d` Detailed or `-t` Trend is requested, the saved securities will be included. If a symbol is added on the command line it will be shown along with those that are saved. If `-s` is provided and there are already saved securities, the current list will overwrite the old list |
|-r | Remove saved securities. If you'd like them back you'll need to re-save them |
|-i | Ignore saved queries for this execution. They will remain saved |

#### Security Information
|Option|Description|
|------|-----------|
|-d | Display detailed stock information for the symbols provided. This is simply additional information retreived from IEXCloud|
|-t | After the initial quote information, display a three month historical view of close prices. Please note that this call is heavily weighted by IEXCLOUD and will use quite a few messages|
|-x FILENAME| Export the results into the specified file in CSV format|
|-x FileName| Export the results into the specified file in CSV format. Note it needs to be a location can can be written to by the user|

#### Misc
|Option|Description|
|------|-----------|
|-D | Start in Debug Mode which will display additional debugging data. Normally not used|
|-v | Display the version and exit|
|-k | Display the configured IEX secret API key and exit|
|-h or -?| Display the help page|

## Parameters
Expand Down
Binary file modified graphics/ScreenShot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.fross</groupId>
<artifactId>quoter</artifactId>
<version>2.1.3</version>
<version>2.2.0</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: '2.1.3'
version: '2.2.0'
summary: Command line utility to pull stock and index quotes
description: |
Quote fetches stock quotes and index data from IEXCloud.IO.
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/org/fross/quoter/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ public static void Display() {
Output.printColorln(Ansi.Color.WHITE, "Command Line Options");

Output.printColorln(Ansi.Color.YELLOW, "\nConfiguration:");
Output.printColorln(Ansi.Color.WHITE, " -c Configure the IEXCloud secret key. See link above for details.");
Output.printColorln(Ansi.Color.WHITE, " -k Display the IEXCloud secret key being used");

Output.printColorln(Ansi.Color.WHITE, " -c Configure the IEXCloud secret key. See link above for details.");
Output.printColorln(Ansi.Color.WHITE, " -k Display the IEXCloud secret key being used");
Output.printColorln(Ansi.Color.WHITE, " -s Save securities as default and show them automatically");
Output.printColorln(Ansi.Color.WHITE, " -r Remove saved securities");
Output.printColorln(Ansi.Color.WHITE, " -i Ignore saved queries for this execution only");

Output.printColorln(Ansi.Color.YELLOW, "\nSecurity Information:");
Output.printColorln(Ansi.Color.WHITE, " -d Display more detailed security information");
Output.printColorln(Ansi.Color.WHITE, " -t Include a 3 month historical trend");
Output.printColorln(Ansi.Color.WHITE, " -d Display more detailed security information");
Output.printColorln(Ansi.Color.WHITE, " -t Include a 3 month historical trend");
Output.printColorln(Ansi.Color.WHITE, " -x File Export data to the provided filename");

Output.printColorln(Ansi.Color.YELLOW, "\nMisc:");
Output.printColorln(Ansi.Color.WHITE, " -D Start in debug mode and display developer information");
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/fross/quoter/HistoricalQuotes.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.Map;
import java.util.TreeMap;

import org.fross.library.Format;
import org.fross.library.Output;
import org.fusesource.jansi.Ansi;

Expand Down
90 changes: 67 additions & 23 deletions src/main/java/org/fross/quoter/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,21 @@ public class Main {
public static String VERSION;
public static String COPYRIGHT;
public static final String PROPERTIES_FILE = "app.properties";
public static final String PREFS_IEXCLOUDTOKEN = "iexcloudtoken";
public static final String PREFS_SAVED_SYMBOLS = "savedsymbols";

public static void main(String[] args) {
int optionEntry;
String iexCloudToken;
String latestTime = "None";
FileExporter exporter = null;
ArrayList<String> symbolList = new ArrayList<String>();

// Command line flags
boolean exportFlag = false;
boolean trendFlag = false;
boolean detailedFlag = false;
FileExporter exporter = null;
boolean saveSymbolsflag = false;
boolean ignoreSavedFlag = false;

// Process application level properties file
// Update properties from Maven at build time:
Expand All @@ -74,15 +80,15 @@ public static void main(String[] args) {
}

// Process Command Line Options
Getopt optG = new Getopt("quote", args, "Dtdckx:h?v");
Getopt optG = new Getopt("quote", args, "ckdtx:sriDvh?");
while ((optionEntry = optG.getopt()) != -1) {
switch (optionEntry) {
// Turn on Debug Mode
case 'D':
Debug.enable();
break;

// Show detailed stock information
// Show Detailed Stock Information
case 'd':
detailedFlag = true;
break;
Expand All @@ -92,14 +98,34 @@ public static void main(String[] args) {
trendFlag = true;
break;

// Save command line securities
case 's':
saveSymbolsflag = true;
break;

// Remove saved securities
case 'r':
Prefs.remove(PREFS_SAVED_SYMBOLS);
break;

// Ignore saved securities
case 'i':
ignoreSavedFlag = true;
break;

// Configure IEXCloud Secret Key
case 'c':
Scanner scanner = new Scanner(System.in);
Output.printColorln(Ansi.Color.WHITE, "Enter the IEXcloud.io Secret Token: ");
iexCloudToken = scanner.next();
Output.debugPrint("Setting Preference iexcloudtoken: " + iexCloudToken);
Prefs.Set("iexcloudtoken", iexCloudToken);
Output.printColorln(Ansi.Color.YELLOW, "IEXCloud.io Secret Token Set To: '" + Prefs.QueryString("iexcloudtoken") + "'");
Prefs.set(PREFS_IEXCLOUDTOKEN, scanner.next());
Output.debugPrint("Setting Preference for iexcloudtoken: " + Prefs.queryString(PREFS_IEXCLOUDTOKEN));
Output.printColorln(Ansi.Color.YELLOW, "IEXCloud.io Secret Token Set To: '" + Prefs.queryString(PREFS_IEXCLOUDTOKEN) + "'");
System.exit(0);
break;

// Display Configured IEXCloud Secret Key
case 'k':
Output.println(Prefs.queryString(PREFS_IEXCLOUDTOKEN));
System.exit(0);
break;

Expand All @@ -109,15 +135,10 @@ public static void main(String[] args) {
exporter = new FileExporter(optG.getOptarg());
break;

// Display configured IEXCloud Secret Key
case 'k':
Output.println(Prefs.QueryString("iexcloudtoken"));
System.exit(0);
break;

// Display version of Quoter and exit
case 'v':
Output.println(VERSION);
Output.println("Quoter Version: v" + VERSION);
Output.println(COPYRIGHT);
System.exit(0);
break;

Expand All @@ -138,21 +159,44 @@ public static void main(String[] args) {

// Read the preferences and make sure that an API key has been entered with the -c
// option
if (Prefs.QueryString("iexcloudtoken") == "Error") {
if (Prefs.queryString(PREFS_IEXCLOUDTOKEN) == "Error") {
Output.fatalError("No iexcloud.io secret token provided. Use '-c' option to configure.", 1);
}

// Display the header
Output.printColorln(Ansi.Color.CYAN, "\nQuoter v" + VERSION + " " + COPYRIGHT);

// Build an array list of symbols entered in on the command line
Output.debugPrint("Number of Symbols entered: " + (args.length - optG.getOptind()));
ArrayList<String> symbolList = new ArrayList<String>();
// Build an array list of symbols entered on the command line
Output.debugPrint("Number of Symbols entered on command line: " + (args.length - optG.getOptind()));
for (int i = optG.getOptind(); i < args.length; i++) {
Output.debugPrint("Symbol entered on commandline: " + args[i]);
symbolList.add(args[i]);
}

// Save the symbols on the command line to preferences as a space delimited list
if (saveSymbolsflag == true && symbolList.isEmpty() == false) {
String flatSymbolList = "";
for (String i : symbolList) {
flatSymbolList += i + " ";
}
Output.debugPrint("Saving the following symbols to preferences: '" + flatSymbolList.trim() + "'");
Prefs.set(PREFS_SAVED_SYMBOLS, flatSymbolList.trim());

// Empty the symbol list after saving as they will be added back below. Don't want it twice
symbolList.clear();
}

// Add any saved symbols to the list of symbols to process
if (ignoreSavedFlag == false) {
Output.debugPrint("Adding saved symbols: '" + Prefs.queryString(PREFS_SAVED_SYMBOLS) + "'");
String[] savedSymbols = Prefs.queryString(PREFS_SAVED_SYMBOLS).split(" ");
for (String i : savedSymbols) {
if (i != "Error") {
symbolList.add(i);
}
}
}

// If symbols were entered, display the header for them
if (symbolList.size() > 0) {
Output.printColorln(Ansi.Color.CYAN, "-------------------------------------------------------------------------------");
Expand All @@ -172,7 +216,7 @@ public static void main(String[] args) {
String[] outString = new String[9];

// Create the symbol object
Symbol symbolData = new Symbol(currentSymbol, Prefs.QueryString("iexcloudtoken"));
Symbol symbolData = new Symbol(currentSymbol, Prefs.queryString(PREFS_IEXCLOUDTOKEN));

// Validate the provided quote is valid
if (symbolData.get("status").compareTo("Error") == 0) {
Expand Down Expand Up @@ -335,7 +379,7 @@ public static void main(String[] args) {
// Display date of the data as pulled from iecloud.net. If no symbols were provided and
// just index data is displayed, grab a security in order to get the date
if (symbolList.isEmpty()) {
Symbol getTime = new Symbol("IBM", Prefs.QueryString("iexcloudtoken"));
Symbol getTime = new Symbol("IBM", Prefs.queryString(PREFS_IEXCLOUDTOKEN));
latestTime = getTime.get("latestUpdate");
}
Output.printColorln(Ansi.Color.CYAN, "\nData as of " + latestTime);
Expand All @@ -352,7 +396,7 @@ public static void main(String[] args) {
// Loop through each symbol and show the detailed display
for (String symb : symbolList) {
// Create the symbol data object
Symbol symbolData = new Symbol(symb, Prefs.QueryString("iexcloudtoken"));
Symbol symbolData = new Symbol(symb, Prefs.queryString(PREFS_IEXCLOUDTOKEN));

// Display Header
Output.printColorln(Ansi.Color.CYAN, "-".repeat(HEADERWIDTH));
Expand All @@ -371,7 +415,7 @@ public static void main(String[] args) {
// Display trending data if -t was provided and there is at least one symbol
if (trendFlag == true && !symbolList.isEmpty()) {
for (String i : symbolList) {
HistoricalQuotes.displayTrendingMap(i, Prefs.QueryString("iexcloudtoken"));
HistoricalQuotes.displayTrendingMap(i, Prefs.queryString(PREFS_IEXCLOUDTOKEN));
}
}

Expand Down
22 changes: 15 additions & 7 deletions src/main/java/org/fross/quoter/Prefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Prefs {
* @param key
* @return
*/
public static boolean QueryBoolean(String key) {
public static boolean queryBoolean(String key) {
return prefs.getBoolean(key, false);
}

Expand All @@ -59,7 +59,7 @@ public static boolean QueryBoolean(String key) {
* @param key
* @return
*/
public static Double QueryDouble(String key) {
public static Double queryDouble(String key) {
return prefs.getDouble(key, 0);
}

Expand All @@ -69,7 +69,7 @@ public static Double QueryDouble(String key) {
* @param key
* @return
*/
public static String QueryString(String key) {
public static String queryString(String key) {
return prefs.get(key, "Error");
}

Expand All @@ -79,7 +79,7 @@ public static String QueryString(String key) {
* @param key
* @param value
*/
public static void Set(String key, boolean value) {
public static void set(String key, boolean value) {
prefs.putBoolean(key, value);
}

Expand All @@ -89,7 +89,7 @@ public static void Set(String key, boolean value) {
* @param key
* @param value
*/
public static void Set(String key, int value) {
public static void set(String key, int value) {
prefs.putInt(key, value);
}

Expand All @@ -99,7 +99,7 @@ public static void Set(String key, int value) {
* @param key
* @param value
*/
public static void Set(String key, double value) {
public static void set(String key, double value) {
prefs.putDouble(key, value);
}

Expand All @@ -109,7 +109,15 @@ public static void Set(String key, double value) {
* @param key
* @param value
*/
public static void Set(String key, String value) {
public static void set(String key, String value) {
prefs.put(key, value);
}

/**
* remove(): Remove the provided preference
* @param key
*/
public static void remove(String key) {
prefs.remove(key);
}
}

0 comments on commit 27ed08f

Please sign in to comment.