Skip to content

Commit

Permalink
Handle connection error
Browse files Browse the repository at this point in the history
  • Loading branch information
gmasse committed Sep 22, 2023
1 parent 6ca240e commit 31b58ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion yf_stock_ticker/yf_stock_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
""" xbar plugin
--Use Yahoo Finance data to monitor stock indices, currencies and cryptocurrencies """

import sys
import os
import logging

import requests.exceptions
from yahooquery import Ticker


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

quotes = Ticker(symbols)
data = quotes.price

try:
data = quotes.price
except requests.exceptions.ConnectionError:
log.warning("Cannot get data")
return None

for symbol in symbols:
if not isinstance(data[symbol], dict):
log.warning("Quote not found for symbol: %s", symbol)
Expand Down Expand Up @@ -102,6 +110,10 @@ def main():
unique_symbols = SYMBOLS_TICKER + list(set(SYMBOLS_DROPDOWN) - set(SYMBOLS_TICKER))
quotes = get_quotes(unique_symbols)

if quotes is None:
print("⚠️ connection failed | color=gray")
sys.exit(0)

if len(SYMBOLS_TICKER) == 0:
print("xbar")
else:
Expand Down
2 changes: 1 addition & 1 deletion yf_stock_ticker/yf_stock_ticker.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
# <xbar.title>YF Stock Ticker</xbar.title>
# <xbar.version>v0.3-beta</xbar.version>
# <xbar.version>v0.4-beta</xbar.version>
# <xbar.author>Germain Masse</xbar.author>
# <xbar.author.github>gmasse</xbar.author.github>
# <xbar.desc>--Use Yahoo Finance data to monitor stock indices, currencies and cryptocurrencies</xbar.desc>
Expand Down

0 comments on commit 31b58ae

Please sign in to comment.