Skip to content

Commit 31b58ae

Browse files
committed
Handle connection error
1 parent 6ca240e commit 31b58ae

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

yf_stock_ticker/yf_stock_ticker.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
""" xbar plugin
33
--Use Yahoo Finance data to monitor stock indices, currencies and cryptocurrencies """
44

5+
import sys
56
import os
67
import logging
78

9+
import requests.exceptions
810
from yahooquery import Ticker
911

1012

@@ -29,7 +31,13 @@ def get_quotes(symbols):
2931
""" Get quotes with yahooquery """
3032

3133
quotes = Ticker(symbols)
32-
data = quotes.price
34+
35+
try:
36+
data = quotes.price
37+
except requests.exceptions.ConnectionError:
38+
log.warning("Cannot get data")
39+
return None
40+
3341
for symbol in symbols:
3442
if not isinstance(data[symbol], dict):
3543
log.warning("Quote not found for symbol: %s", symbol)
@@ -102,6 +110,10 @@ def main():
102110
unique_symbols = SYMBOLS_TICKER + list(set(SYMBOLS_DROPDOWN) - set(SYMBOLS_TICKER))
103111
quotes = get_quotes(unique_symbols)
104112

113+
if quotes is None:
114+
print("⚠️ connection failed | color=gray")
115+
sys.exit(0)
116+
105117
if len(SYMBOLS_TICKER) == 0:
106118
print("xbar")
107119
else:

yf_stock_ticker/yf_stock_ticker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
# <xbar.title>YF Stock Ticker</xbar.title>
3-
# <xbar.version>v0.3-beta</xbar.version>
3+
# <xbar.version>v0.4-beta</xbar.version>
44
# <xbar.author>Germain Masse</xbar.author>
55
# <xbar.author.github>gmasse</xbar.author.github>
66
# <xbar.desc>--Use Yahoo Finance data to monitor stock indices, currencies and cryptocurrencies</xbar.desc>

0 commit comments

Comments
 (0)