From 514ca570670f0a262439a3138dd566676f04cc52 Mon Sep 17 00:00:00 2001 From: Scott Alfter Date: Tue, 30 Jan 2018 08:20:28 -0800 Subject: [PATCH] reliability updates --- zpool-switch.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/zpool-switch.py b/zpool-switch.py index 9cb73bf..ae9a37c 100755 --- a/zpool-switch.py +++ b/zpool-switch.py @@ -40,22 +40,30 @@ try: exchrate=float(json.loads(fetch("https://api.coinbase.com/v2/exchange-rates?currency=BTC"))["data"]["rates"][currency]) data=json.loads(fetch("http://www.zpool.ca/api/status")) except: - print("unable to retrieve remote data", file=sys.stderr) - sys.exit(-1) + if (len(sys.argv)!=5): + print("unable to retrieve remote data", file=sys.stderr) + sys.exit(-1) + else: + pass # update algo map -changed=False -for i in data: - try: - k=algo_map[i] - except: - algo_map[i]="" - changed=True +try: + changed=False + for i in data: + try: + k=algo_map[i] + except: + algo_map[i]="" + changed=True -if (changed==True): - with open(sys.argv[3], "w") as outfile: - json.dump(algo_map, outfile, sort_keys=True, indent=2) + if (changed==True): + with open(sys.argv[3], "w") as outfile: + json.dump(algo_map, outfile, sort_keys=True, indent=2) +except: + print("null response from server", file=sys.stderr) + sys.exit(-1) + # weed out miners not supported by the pool