From 6d269c74667981da74f1587a824a2399e10d6a76 Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Sun, 7 Nov 2021 11:43:42 -0700 Subject: [PATCH] add weights to trending based on command #84 --- bot.py | 6 +++--- symbol_router.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bot.py b/bot.py index eb976ae..70449f6 100644 --- a/bot.py +++ b/bot.py @@ -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] diff --git a/symbol_router.py b/symbol_router.py index 63858bf..501cbea 100644 --- a/symbol_router.py +++ b/symbol_router.py @@ -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