diff --git a/polybar/scripts/bitcoin.py b/polybar/scripts/bitcoin.py index cf1ee60..922eae8 100755 --- a/polybar/scripts/bitcoin.py +++ b/polybar/scripts/bitcoin.py @@ -2,7 +2,9 @@ import requests -r = requests.get('https://blockchain.info/ticker'); -ticker = r.json() - -print('£%.2f' % float(ticker['GBP']['sell'])) +try: + r = requests.get('https://blockchain.info/ticker'); + ticker = r.json() + print('£%.2f' % float(ticker['GBP']['sell'])) +except requests.exceptions.RequestException as e: + sys.exit(1) diff --git a/polybar/scripts/ipaddr.py b/polybar/scripts/ipaddr.py index 3654fdc..2020216 100755 --- a/polybar/scripts/ipaddr.py +++ b/polybar/scripts/ipaddr.py @@ -4,12 +4,12 @@ from xml.etree import ElementTree as ET url = 'http://freegeoip.net/xml/' -with urlopen(url) as res: - s = res.read() - -root = ET.fromstring(s) - -ip = root.find('IP').text -country = root.find('CountryName').text - -print('%s (%s)' % (ip, country)) +try: + with urlopen(url) as res: + s = res.read() + root = ET.fromstring(s) + ip = root.find('IP').text + country = root.find('CountryName').text + print('%s (%s)' % (ip, country)) +except Exception: + print('') diff --git a/polybar/scripts/ping.py b/polybar/scripts/ping.py index d2693c4..3990a21 100755 --- a/polybar/scripts/ping.py +++ b/polybar/scripts/ping.py @@ -3,5 +3,5 @@ import subprocess import re url = 'google.co.uk' -ps = subprocess.Popen('ping -c 1 %s | tail -1 | awk \'{print $4}\' | cut -d \'/\' -f 2' % url, shell=True, stdout=subprocess.PIPE) +ps = subprocess.Popen('ping -c 1 %s | tail -1' % url, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) print(re.sub(r'[^0-9.+]', '', str(ps.stdout.read())).split('.')[0])