Change watchlist write function name
parent
7e92df4352
commit
6b72d04427
10
piker/cli.py
10
piker/cli.py
|
@ -159,7 +159,7 @@ def show(ctx, name):
|
|||
@click.pass_context
|
||||
def load(ctx, data):
|
||||
try:
|
||||
wl.write_sorted_json(json.loads(data), ctx.obj['path'])
|
||||
wl.write_to_file(json.loads(data), ctx.obj['path'])
|
||||
except (json.JSONDecodeError, IndexError):
|
||||
click.echo('You have passed an invalid text respresentation of a '
|
||||
'JSON object. Try again.')
|
||||
|
@ -172,7 +172,7 @@ def load(ctx, data):
|
|||
def add(ctx, name, ticker_name):
|
||||
watchlist = wl.add_ticker(name, ticker_name,
|
||||
ctx.obj['watchlist'])
|
||||
wl.write_sorted_json(watchlist, ctx.obj['path'])
|
||||
wl.write_to_file(watchlist, ctx.obj['path'])
|
||||
|
||||
|
||||
@watchlists.command(help='remove ticker from watchlist')
|
||||
|
@ -181,7 +181,7 @@ def add(ctx, name, ticker_name):
|
|||
@click.pass_context
|
||||
def remove(ctx, name, ticker_name):
|
||||
watchlist = wl.remove_ticker(name, ticker_name, ctx.obj['watchlist'])
|
||||
wl.write_sorted_json(watchlist, ctx.obj['path'])
|
||||
wl.write_to_file(watchlist, ctx.obj['path'])
|
||||
|
||||
|
||||
@watchlists.command(help='delete watchlist group')
|
||||
|
@ -189,7 +189,7 @@ def remove(ctx, name, ticker_name):
|
|||
@click.pass_context
|
||||
def delete(ctx, name):
|
||||
watchlist = wl.delete_group(name, ctx.obj['watchlist'])
|
||||
wl.write_sorted_json(watchlist, ctx.obj['path'])
|
||||
wl.write_to_file(watchlist, ctx.obj['path'])
|
||||
|
||||
|
||||
@watchlists.command(help='merge a watchlist from another user')
|
||||
|
@ -198,7 +198,7 @@ def delete(ctx, name):
|
|||
def merge(ctx, watchlist_to_merge):
|
||||
merged_watchlist = wl.merge_watchlist(json.loads(watchlist_to_merge),
|
||||
ctx.obj['watchlist'])
|
||||
wl.write_sorted_json(merged_watchlist, ctx.obj['path'])
|
||||
wl.write_to_file(merged_watchlist, ctx.obj['path'])
|
||||
|
||||
|
||||
@watchlists.command(help='dump text respresentation of a watchlist to console')
|
||||
|
|
|
@ -11,7 +11,7 @@ _builtins = {
|
|||
}
|
||||
|
||||
|
||||
def write_sorted_json(watchlist, path):
|
||||
def write_to_file(watchlist, path):
|
||||
for key in watchlist:
|
||||
watchlist[key] = sorted(list(set(watchlist[key])))
|
||||
with open(path, 'w') as f:
|
||||
|
|
|
@ -112,7 +112,7 @@ def piker_dir(temp_dir):
|
|||
'pharma': ['ATE.VN'],
|
||||
'indexes': ['SPY', 'DAX', 'QQQ', 'DIA'],
|
||||
}
|
||||
wl.write_sorted_json(watchlist, json_file_path)
|
||||
wl.write_to_file(watchlist, json_file_path)
|
||||
yield json_file_path
|
||||
|
||||
|
||||
|
@ -201,7 +201,7 @@ def test_watchlists_are_merged(capfd, piker_dir):
|
|||
'pharma': ['ATE.VN', 'MALI', 'PERCOCET'],
|
||||
'drugs': ['CRACK']
|
||||
}
|
||||
wl.write_sorted_json(orig_watchlist, piker_dir)
|
||||
wl.write_to_file(orig_watchlist, piker_dir)
|
||||
run(f"piker watchlists -d {piker_dir} merge", list_to_merge)
|
||||
out = wl.ensure_watchlists(piker_dir)
|
||||
assert out == expected_out
|
||||
|
|
|
@ -30,7 +30,7 @@ def test_watchlist_is_sorted_no_dups_and_saved_to_file(piker_dir):
|
|||
wl_temp = {'test': ['TEST.CN', 'AAA'], 'AA': ['TEST.CN', 'TEST.CN'],
|
||||
'AA': ['TEST.CN']}
|
||||
wl_sort = {'AA': ['TEST.CN'], 'test': ['AAA', 'TEST.CN']}
|
||||
wl.write_sorted_json(wl_temp, piker_dir)
|
||||
wl.write_to_file(wl_temp, piker_dir)
|
||||
temp_sorted = wl.ensure_watchlists(piker_dir)
|
||||
assert temp_sorted == wl_sort
|
||||
|
||||
|
@ -60,7 +60,7 @@ def test_watchlist_is_read_from_file(piker_dir):
|
|||
wl_temp = wl.ensure_watchlists(piker_dir)
|
||||
assert wl_temp == {}
|
||||
wl_temp2 = {"AA": ["TEST.CN"]}
|
||||
wl.write_sorted_json(wl_temp2, piker_dir)
|
||||
wl.write_to_file(wl_temp2, piker_dir)
|
||||
assert wl_temp2 == wl.ensure_watchlists(piker_dir)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue