diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 500f8e9..3b76032 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,3 +1,10 @@ +black: + stage: .pre + 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 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 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 b35183d..e34b53d 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 @@ -30,15 +31,16 @@ class Router: def trending_decay(self, decay=0.5): """Decays the value of each trending stock by a multiplier""" - return - 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 @@ -400,6 +402,7 @@ class Router: return replies + @cached(cache=TTLCache(maxsize=1024, ttl=600)) def trending(self) -> str: """Checks APIs for trending symbols.