Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
Hemna | 1c2d0a4006 | |
Hemna | fd5f92d22a | |
Hemna | a226f0486f |
|
@ -0,0 +1,17 @@
|
|||
CHANGES
|
||||
=======
|
||||
|
||||
v0.1.2
|
||||
------
|
||||
|
||||
* Updated README
|
||||
|
||||
v0.1.1
|
||||
------
|
||||
|
||||
* Working plugin pulled from aprsd itself
|
||||
|
||||
v0.1.0
|
||||
------
|
||||
|
||||
* Initial commit
|
|
@ -36,13 +36,7 @@ APRSD Yahoo Finance Stock Quotes
|
|||
Features
|
||||
--------
|
||||
|
||||
* TODO
|
||||
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
* TODO
|
||||
* APRSD Plugin that gets a stock quote from Yahoo Finance python API and returns that.
|
||||
|
||||
|
||||
Installation
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
import logging
|
||||
|
||||
from aprsd import messaging, plugin, trace
|
||||
|
||||
import aprsd_stock_plugin
|
||||
|
||||
|
||||
LOG = logging.getLogger("APRSD")
|
||||
|
||||
|
||||
class YahooStockQuote(plugin.APRSDRegexCommandPluginBase):
|
||||
|
||||
version = aprsd_stock_plugin.__version__
|
||||
# Look for any command that starts with w or W
|
||||
command_regex = "^[wW]"
|
||||
# the command is for ?
|
||||
command_name = "weather"
|
||||
|
||||
enabled = False
|
||||
|
||||
def setup(self):
|
||||
# Do some checks here?
|
||||
self.enabled = True
|
||||
|
||||
def create_threads(self):
|
||||
"""This allows you to create and return a custom APRSDThread object.
|
||||
|
||||
Create a child of the aprsd.threads.APRSDThread object and return it
|
||||
It will automatically get started.
|
||||
|
||||
You can see an example of one here:
|
||||
https://github.com/craigerl/aprsd/blob/master/aprsd/threads.py#L141
|
||||
"""
|
||||
if self.enabled:
|
||||
# You can create a background APRSDThread object here
|
||||
# Just return it for example:
|
||||
# https://github.com/hemna/aprsd-weewx-plugin/blob/master/aprsd_weewx_plugin/aprsd_weewx_plugin.py#L42-L50
|
||||
#
|
||||
return []
|
||||
|
||||
@trace.trace
|
||||
def process(self, packet):
|
||||
|
||||
"""This is called when a received packet matches self.command_regex."""
|
||||
|
||||
LOG.info("YahooStockQuote Plugin")
|
||||
|
||||
packet.get("from")
|
||||
packet.get("message_text", None)
|
||||
|
||||
if self.enabled:
|
||||
# Now we can process
|
||||
return "some reply message"
|
||||
else:
|
||||
LOG.warning("YahooStockQuote is disabled.")
|
||||
return messaging.NULL_MESSAGE
|
|
@ -0,0 +1,60 @@
|
|||
import logging
|
||||
import re
|
||||
|
||||
import yfinance as yf
|
||||
from aprsd import plugin
|
||||
|
||||
import aprsd_stock_plugin
|
||||
|
||||
|
||||
LOG = logging.getLogger("APRSD")
|
||||
|
||||
|
||||
class YahooStockQuote(plugin.APRSDRegexCommandPluginBase):
|
||||
|
||||
version = aprsd_stock_plugin.__version__
|
||||
|
||||
# Look for any command that starts with s or S
|
||||
command_regex = "^[sS]"
|
||||
|
||||
# the command is for ?
|
||||
command_name = "stock"
|
||||
|
||||
enabled = False
|
||||
|
||||
def setup(self):
|
||||
# Do some checks here?
|
||||
self.enabled = True
|
||||
|
||||
def process(self, packet):
|
||||
LOG.info(self.__class__.__name__)
|
||||
|
||||
# fromcall = packet.get("from")
|
||||
message = packet.get("message_text", None)
|
||||
# ack = packet.get("msgNo", "0")
|
||||
|
||||
a = re.search(r"^.*\s+(.*)", message)
|
||||
if a is not None:
|
||||
searchcall = a.group(1)
|
||||
stock_symbol = searchcall.upper()
|
||||
else:
|
||||
reply = "No stock symbol"
|
||||
return reply
|
||||
|
||||
LOG.info(f"Fetch stock quote for '{stock_symbol}'")
|
||||
|
||||
try:
|
||||
stock = yf.Ticker(stock_symbol)
|
||||
reply = "{} - ask: {} high: {} low: {}".format(
|
||||
stock_symbol,
|
||||
stock.info["ask"],
|
||||
stock.info["dayHigh"],
|
||||
stock.info["dayLow"],
|
||||
)
|
||||
except Exception as e:
|
||||
LOG.error(
|
||||
f"Failed to fetch stock '{stock_symbol}' from yahoo '{e}'",
|
||||
)
|
||||
reply = f"Failed to fetch stock '{stock_symbol}'"
|
||||
|
||||
return reply.rstrip()
|
|
@ -1,2 +1,3 @@
|
|||
pbr
|
||||
aprsd>=2.2.0
|
||||
aprsd>=2.4.0
|
||||
yfinance
|
||||
|
|
Loading…
Reference in New Issue