summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid McMackins II <contact@mcmackins.org>2015-08-29 11:40:23 -0500
committerDavid McMackins II <contact@mcmackins.org>2015-08-29 11:40:23 -0500
commit202443f9ace8b8aba933ba2041d65eed3fb02e2f (patch)
tree90395b90a941ee4436191d295f1efbd167ff17d9
parent1c00921348ae514fd6ce86bb73eaa8278f1ca2ed (diff)
Added option to list the installed APIs
-rwxr-xr-xcoinfetch23
1 files changed, 16 insertions, 7 deletions
diff --git a/coinfetch b/coinfetch
index ec9b7fa..9c1c562 100755
--- a/coinfetch
+++ b/coinfetch
@@ -30,15 +30,30 @@ There is NO WARRANTY, to the extent permitted by law.
Written by {}'''.format(__title__, __version__, __author__)
+def list_sorted_apis():
+ tickers = get_registered_tickers()
+ tickers.sort()
+ for api, desc in tickers:
+ print(api + '\t- ' + desc)
+
+class ListAction(Action):
+ def __call__(self, parser, values, namespace, option_string):
+ list_sorted_apis()
+ exit(0)
+
class VersionAction(Action):
def __call__(self, parser, values, namespace, option_string):
print(__version_info__)
exit(0)
+load_default_plugins()
+
cli = ArgumentParser(__title__)
cli.add_argument('-a', '--api', default='btce', help='uses an API by name')
cli.add_argument('-k', '--kind', help='specifies which kind of rate to get')
+cli.add_argument('-l', '--list-apis', action=ListAction,
+ help='list available APIs and exit', nargs=0)
cli.add_argument('-v', '--version', action=VersionAction,
help='show version information and exit', nargs=0)
@@ -49,18 +64,12 @@ cli.add_argument('dest', help='currency to which to convert')
args = cli.parse_args()
-load_default_plugins()
-
try:
print('%.8f' %get_ticker(args.api).get_rate(args.src, args.dest, args.amount))
except KeyError:
print('The API {} is not available. Currently installed APIs:'.format(args.api))
- tickers = get_registered_tickers()
- tickers.sort()
- for api, desc in tickers:
- print(api + '\t- ' + desc)
-
+ list_sorted_apis()
exit(10)
except ValueError:
pair = '/'.join([args.src, args.dest])