From 792a068792044141f1a26048490b07bee64978c0 Mon Sep 17 00:00:00 2001 From: Julien Riou Date: Mon, 25 Jan 2021 13:08:01 +0100 Subject: [PATCH] Make fiat currency optional Signed-off-by: Julien Riou --- README.md | 2 +- main.py | 16 ++++++++-------- templates/balance.md.j2 | 2 +- templates/block.md.j2 | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0d6a9ec..85b8ff1 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ bot. You'll need the `chat_id` and `auth_key` for the next section. Configuration file use the JSON format with the following keys: * `miner`: wallet address of the miner -* `currency`: symbol of the currency to convert (default: USD) +* `currency`: symbol of the currency to convert (optional) * `telegram`: send notifications with Telegram (optional) * `auth_key`: Telegram authentication key for the bot API * `chat_id`: Telegram chat room id (where to send the message) diff --git a/main.py b/main.py index cf59ebd..4413b20 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,6 @@ logger = logging.getLogger(__name__) DEFAULT_STATE_FILE = 'state.json' -DEFAULT_CURRENCY = 'USD' def parse_arguments(): @@ -104,14 +103,15 @@ def main(): state = read_state(state_file) exchange_rate = None - currency = config.get('currency', DEFAULT_CURRENCY) + currency = config.get('currency') - logger.debug('fetching current rate') - try: - exchange_rate = get_rate(ids='ethereum', vs_currencies=currency) - except HTTPError as err: - logger.warning(f'failed to get ETH/{currency} rate') - logger.debug(str(err)) + if currency: + logger.debug('fetching current rate') + try: + exchange_rate = get_rate(ids='ethereum', vs_currencies=currency) + except HTTPError as err: + logger.warning(f'failed to get ETH/{currency} rate') + logger.debug(str(err)) block = watch_block(last_block=state.get('block'), config=config, disable_notifications=args.disable_notifications, exchange_rate=exchange_rate, currency=currency) diff --git a/templates/balance.md.j2 b/templates/balance.md.j2 index 07030f7..d36c007 100644 --- a/templates/balance.md.j2 +++ b/templates/balance.md.j2 @@ -1,5 +1,5 @@ *💰 New balance* *Address*: {{address}} -*Unpaid balance*: {{balance}} {% if balance_fiat %}\({{balance_fiat}}\){% endif %} +*Unpaid balance*: {{balance}} {% if balance_fiat != 'None' %}\({{balance_fiat}}\){% endif %} *Unpaid percentage*: {{balance_percentage}} diff --git a/templates/block.md.j2 b/templates/block.md.j2 index 91459da..0af6e15 100644 --- a/templates/block.md.j2 +++ b/templates/block.md.j2 @@ -1,6 +1,6 @@ *⛏️ New block {{number}}* *Date/Time*: {{time}} -*Reward*: {{reward}} {% if reward_fiat %}\({{reward_fiat}}\){% endif %} +*Reward*: {{reward}} {% if reward_fiat != 'None' %}\({{reward_fiat}}\){% endif %} *Round time*: {{round_time}} *Luck*: {{luck}}