Ticker: Add a stock ticker plugin (#822)

Pull stock info from Yahoo (via yfinance) and display a customizable ticker.

Signed-off-by: David Wahlstrom <david.wahlstrom@gmail.com>
This commit is contained in:
David Wahlstrom 2021-08-19 11:38:43 -06:00 committed by GitHub
parent d0912be27e
commit ac71437b29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 1 deletions

View File

@ -68,7 +68,8 @@ MOCK_MODULES = [
"requests.adapters",
"exchangelib",
"soco",
"tesla_api"
"tesla_api",
"yfinance"
]
for mod_name in MOCK_MODULES:

48
i3pystatus/ticker.py Normal file
View File

@ -0,0 +1,48 @@
from i3pystatus import IntervalModule
import yfinance as yf
class Ticker(IntervalModule):
"""
Displays stock ticker information from yahoo finance
Requires: yfinance
"""
settings = (
("symbol", "Stock symbol to track"),
("interval", "Update interval (in seconds)"),
("good_color", "Color of text while 'regularMarketPrice' is above "
"good_threshold"),
("bad_color", "Color of text while 'regularMarketPrice' is below "
"bad_threshold"),
("caution_color", "Color of text while 'regularMarketPrice' is between good "
"and bad thresholds"),
("good_threshold", "The target value for consindering the stock a good value"),
("bad_threshold", "The target value for consindering the stock a poor value"),
"format"
)
#required = "symbol"
good_color = "#00FF00" # green
caution_color = "#FFFF00" # yellow
bad_color = "#FF0000" # red
good_threshold = 100
bad_threshold = 50
interval = 300
format = "{symbol}: {regularMarketPrice} ({regularMarketDayHigh}/{regularMarketDayLow})"
def run(self):
stock = yf.Ticker(self.symbol)
tick = stock.info
if tick['regularMarketPrice'] >= float(self.good_threshold):
color = self.good_color
elif tick['regularMarketPrice'] <= float(self.bad_threshold):
color = self.bad_color
else:
color = self.caution_color
self.output = {
"full_text": self.format.format(**tick),
"color": color
}