From 8a72386a3037681c11fe266fa5181d3a52e00dbe Mon Sep 17 00:00:00 2001 From: Nils Date: Fri, 30 Mar 2018 09:58:14 +0200 Subject: [PATCH] print magic value U if error --- .../currency/zcash/zcash_flypool_hashrate_ | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/plugins/currency/zcash/zcash_flypool_hashrate_ b/plugins/currency/zcash/zcash_flypool_hashrate_ index 609c1aa9..4eec991d 100755 --- a/plugins/currency/zcash/zcash_flypool_hashrate_ +++ b/plugins/currency/zcash/zcash_flypool_hashrate_ @@ -82,24 +82,25 @@ except IOError as exc: print("Failed to request Flypool API: {}".format(exc), file=sys.stderr) sys.exit(9) +# manage codec and error handling lookup process reader = codecs.getreader("utf-8") try: mining_stats = json.load(reader(mining_stats_raw)) except ValueError: print("Failed to parse JSON responce.", file=sys.stderr) - sys.exit(9) - -try: - worker = mining_stats['data'] -except (KeyError, TypeError): - print("JSON result error!", file=sys.stderr) - sys.exit(9) - -try: - hash_rate = worker['currentHashrate'] -except (KeyError, TypeError): - print("No current Hashrate!", file=sys.stderr) - sys.exit(9) - -print("flypool_hs_{}_{}.value {}".format(zcash_address, miner, hash_rate)) + print("flypool_hs_{}_{}.value U".format(zcash_address, miner)) +else: + try: + worker = mining_stats['data'] + except (KeyError, TypeError): + print("JSON result error!", file=sys.stderr) + print("flypool_hs_{}_{}.value U".format(zcash_address, miner)) + else: + try: + hash_rate = worker['currentHashrate'] + except (KeyError, TypeError): + print("No current Hashrate!", file=sys.stderr) + print("flypool_hs_{}_{}.value U".format(zcash_address, miner)) + else: + print("flypool_hs_{}_{}.value {}".format(zcash_address, miner, hash_rate))