From 553b958cc1bc64ccbe8feb6dfa85596b049b4e89 Mon Sep 17 00:00:00 2001 From: Anson Date: Wed, 1 Sep 2021 23:52:53 -0700 Subject: [PATCH 1/8] cache trending command results --- requirements.txt | 3 ++- symbol_router.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 45e4aa1..9615514 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ fuzzywuzzy==0.18.0 python-Levenshtein==0.12.1 schedule==1.0.0 mplfinance==0.12.7a5 -markdownify==0.6.5 \ No newline at end of file +markdownify==0.6.5 +cachetools==4.2.2 \ No newline at end of file diff --git a/symbol_router.py b/symbol_router.py index cc1597e..9940c48 100644 --- a/symbol_router.py +++ b/symbol_router.py @@ -8,6 +8,7 @@ from logging import critical, debug, error, info, warning import pandas as pd import schedule +from cachetools import TTLCache, cached from fuzzywuzzy import fuzz from cg_Crypto import cg_Crypto @@ -399,6 +400,7 @@ class Router: return replies + @cached(cache=TTLCache(maxsize=1024, ttl=600)) def trending(self) -> str: """Checks APIs for trending symbols. From 2cf0adcb22bd7428d885d0fbf8c4160f2c765ae2 Mon Sep 17 00:00:00 2001 From: Anson Date: Wed, 1 Sep 2021 23:52:53 -0700 Subject: [PATCH 2/8] cache trending command results --- requirements.txt | 3 ++- symbol_router.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 45e4aa1..9615514 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ fuzzywuzzy==0.18.0 python-Levenshtein==0.12.1 schedule==1.0.0 mplfinance==0.12.7a5 -markdownify==0.6.5 \ No newline at end of file +markdownify==0.6.5 +cachetools==4.2.2 \ No newline at end of file diff --git a/symbol_router.py b/symbol_router.py index cc1597e..9940c48 100644 --- a/symbol_router.py +++ b/symbol_router.py @@ -8,6 +8,7 @@ from logging import critical, debug, error, info, warning import pandas as pd import schedule +from cachetools import TTLCache, cached from fuzzywuzzy import fuzz from cg_Crypto import cg_Crypto @@ -399,6 +400,7 @@ class Router: return replies + @cached(cache=TTLCache(maxsize=1024, ttl=600)) def trending(self) -> str: """Checks APIs for trending symbols. From 20ec52fc227df58fd967446f3d6ec44fd0b6bb38 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 5 Oct 2021 15:37:39 -0700 Subject: [PATCH 3/8] hopeful fix for #77 --- symbol_router.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/symbol_router.py b/symbol_router.py index 9940c48..e34b53d 100644 --- a/symbol_router.py +++ b/symbol_router.py @@ -31,14 +31,16 @@ class Router: def trending_decay(self, decay=0.5): """Decays the value of each trending stock by a multiplier""" - info("Decaying trending symbols.") if self.trending_count: - for key in self.trending_count.keys(): - if self.trending_count[key] < 0.01: + t_copy = self.trending_count.copy() + for key in t_copy.keys(): + if t_copy[key] < 0.01: # This just makes sure were not keeping around keys that havent been called in a very long time. - self.trending_count.pop(key, None) + t_copy.pop(key, None) else: - self.trending_count[key] = self.trending_count[key] * decay + t_copy[key] = t_copy[key] * decay + self.trending_count = t_copy.copy() + info("Decayed trending symbols.") def find_symbols(self, text: str) -> list[Symbol]: """Finds stock tickers starting with a dollar sign, and cryptocurrencies with two dollar signs From 621e8a75c3df7513547fbdf8f18dc1323d760944 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 5 Oct 2021 15:41:49 -0700 Subject: [PATCH 4/8] add linting step --- .gitlab-ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 500f8e9..0df1002 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,10 @@ +black: + stage: linting + image: registry.gitlab.com/pipeline-components/black:latest + script: + - black --check --verbose -- . + + #Following instructions (as of 2020-04-01): https://docs.gitlab.com/ee/ci/docker/using_kaniko.html #Kaniko docs are here: https://github.com/GoogleContainerTools/kaniko #While this example shows building to multiple registries for all branches, with a few modifications From c81e4ffb0097721fcfaf75504c9f6c7ebd74eabc Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 5 Oct 2021 15:42:39 -0700 Subject: [PATCH 5/8] clean settings --- .vscode/settings.json | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 90f899a..2c898ae 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,13 +8,6 @@ "files.associations": { "DockerDev": "dockerfile", }, - "workbench.colorTheme": "One Dark Pro", - "explorer.confirmDelete": false, - "editor.fontFamily": "JetBrains Mono", - "editor.letterSpacing": 1.2, - "editor.fontLigatures": true, - "editor.wordWrap": "on", "python.formatting.provider": "black", "python.showStartPage": false, - "editor.fontSize": 13, } \ No newline at end of file From 9bb732a2619f086c8944df35aee7e2201ef959eb Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Tue, 5 Oct 2021 22:47:12 +0000 Subject: [PATCH 6/8] Update .gitlab-ci.yml file --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0df1002..3b76032 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,5 @@ black: - stage: linting + stage: .pre image: registry.gitlab.com/pipeline-components/black:latest script: - black --check --verbose -- . From e36082334c76ec79a8486cb8836420fb7fbbea1e Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 5 Oct 2021 15:48:40 -0700 Subject: [PATCH 7/8] seeing what happens if formatting is incorrect --- symbol_router.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/symbol_router.py b/symbol_router.py index e34b53d..80491d9 100644 --- a/symbol_router.py +++ b/symbol_router.py @@ -20,7 +20,7 @@ class Router: STOCK_REGEX = "(?:^|[^\\$])\\$([a-zA-Z.]{1,6})" CRYPTO_REGEX = "[$]{2}([a-zA-Z]{1,20})" searched_symbols = {} - trending_count = {} + trending_count = { } def __init__(self): self.stock = IEX_Symbol() From 0374f5b78973f629d24f5155305aa5c8e0509210 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 5 Oct 2021 15:49:47 -0700 Subject: [PATCH 8/8] fix format error --- symbol_router.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/symbol_router.py b/symbol_router.py index 80491d9..e34b53d 100644 --- a/symbol_router.py +++ b/symbol_router.py @@ -20,7 +20,7 @@ class Router: STOCK_REGEX = "(?:^|[^\\$])\\$([a-zA-Z.]{1,6})" CRYPTO_REGEX = "[$]{2}([a-zA-Z]{1,20})" searched_symbols = {} - trending_count = { } + trending_count = {} def __init__(self): self.stock = IEX_Symbol()