1
0
mirror of https://gitlab.com/simple-stock-bots/simple-stock-bot.git synced 2025-06-15 23:06:40 +00:00

add weights to trending based on command #84

This commit is contained in:
Anson Biggs 2021-11-07 11:43:42 -07:00
parent d26a3cfc78
commit 6d269c7466
2 changed files with 6 additions and 6 deletions

6
bot.py
View File

@ -224,7 +224,7 @@ def news(update: Update, context: CallbackContext):
)
return
symbols = s.find_symbols(message)
symbols = s.find_symbols(message,trending_weight=10)
if symbols:
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
@ -305,7 +305,7 @@ def intra(update: Update, context: CallbackContext):
)
return
symbols = s.find_symbols(message)
symbols = s.find_symbols(message, trending_weight=5)
symbol = symbols[0]
if len(symbols):
@ -361,7 +361,7 @@ def chart(update: Update, context: CallbackContext):
)
return
symbols = s.find_symbols(message)
symbols = s.find_symbols(message, trending_weight=10)
if len(symbols):
symbol = symbols[0]

View File

@ -44,7 +44,7 @@ class Router:
self.trending_count = t_copy.copy()
info("Decayed trending symbols.")
def find_symbols(self, text: str) -> list[Symbol]:
def find_symbols(self, text: str, *, trending_weight: int = 1) -> list[Symbol]:
"""Finds stock tickers starting with a dollar sign, and cryptocurrencies with two dollar signs
in a blob of text and returns them in a list.
@ -79,7 +79,7 @@ class Router:
info(symbols)
for symbol in symbols:
self.trending_count[symbol.tag] = (
self.trending_count.get(symbol.tag, 0) + 1
self.trending_count.get(symbol.tag, 0) + trending_weight
)
return symbols
@ -131,7 +131,7 @@ class Router:
symbols = df.head(matches)
symbols["price_reply"] = symbols["type_id"].apply(
lambda sym: self.price_reply(self.find_symbols(sym))[0]
lambda sym: self.price_reply(self.find_symbols(sym, trending_weight=0))[0]
)
return symbols