From e11ec2a456c030589a8a165a6730100b75f9d3d1 Mon Sep 17 00:00:00 2001 From: Mateo Cruz Date: Wed, 22 Sep 2021 13:09:34 +0530 Subject: [PATCH] bugfix : Add exception handling for lost internet connection see https://github.com/wolfrust/bannoti/issues/12 for more details --- bannoti.py | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/bannoti.py b/bannoti.py index 927ccf6..a004fb8 100644 --- a/bannoti.py +++ b/bannoti.py @@ -3,6 +3,7 @@ from sys import argv from colorama import Fore, Style, init init() +import requests def show_help() -> None: @@ -101,22 +102,35 @@ def removeFromStartup(Name) -> None: while True: - for i in range(len(accounts)): + try: + + for i in range(len(accounts)): + + pending_now = ban.account_balance(accounts[i])['pending'] + pending_then = balances['balances'][accounts[i]]['pending'] - pending_now = ban.account_balance(accounts[i])['pending'] - pending_then = balances['balances'][accounts[i]]['pending'] + if ( pending_now != pending_then ): - if ( pending_now != pending_then ): + if ( not is_negative(pending_now - pending_then)): - if ( not is_negative(pending_now - pending_then)): + print(f'Recieved {str(ban.ban_from_raw(str(pending_now - pending_then)))[0:4]}BAN at account {Fore.YELLOW}{accounts[i][0:7]}{Style.RESET_ALL}{accounts[i][7:61]}{Fore.GREEN}{accounts[i][60:65]}{Style.RESET_ALL}') - print(f'Recieved {str(ban.ban_from_raw(str(pending_now - pending_then)))[0:4]}BAN at account {Fore.YELLOW}{accounts[i][0:7]}{Style.RESET_ALL}{accounts[i][7:61]}{Fore.GREEN}{accounts[i][60:65]}{Style.RESET_ALL}') + if (getOS() == 'Windows'): + exec(r'assets\notify.exe ' + f'"Recieved {str(ban.ban_from_raw(str(pending_now - pending_then)))[0:4]}BAN" "at account {accounts[i]}"') + else: + exec(f'assets/notify "Recieved {str(ban.ban_from_raw(str(pending_now - pending_then)))[0:4]}BAN" "at account {accounts[i]}"') - if (getOS() == 'Windows'): - exec(r'assets\notify.exe ' + f'"Recieved {str(ban.ban_from_raw(str(pending_now - pending_then)))[0:4]}BAN" "at account {accounts[i]}"') - else: - exec(f'assets/notify "Recieved {str(ban.ban_from_raw(str(pending_now - pending_then)))[0:4]}BAN" "at account {accounts[i]}"') + balances['balances'][accounts[i]]['pending'] = pending_now - balances['balances'][accounts[i]]['pending'] = pending_now + sleep(5) - sleep(5) + except (requests.exceptions.ConnectionError, requests.exceptions.ConnectionError) : + print(f"{Fore.RED}Internet connection lost.. {Style.RESET_ALL}", end="") + while True: + sleep(5) + try: + requests.get('https://google.com') + break + except: + pass + print(f"{Fore.GREEN} Restored {Style.RESET_ALL}")