Abstract RapidAPI hostname to more easily handle name changes

This commit is contained in:
Tim 2022-03-05 09:10:15 -05:00
parent 52d53a8637
commit 011dcb2dd5
3 changed files with 11 additions and 4 deletions

View File

@ -1,6 +1,12 @@
# api key to use for https://rapidapi.com/apidojo/api/yahoo-finance1
# API key for RapidAPI https://rapidapi.com/apidojo/api/yahoo-finance1
rapidapiKey: mYsUp3rs3CretKEY12345
# API key for CoinAPI (https://www.coinapi.io/)
coinapiioKey: mYsUp3rs3CretKEY12345
# Triggers
stocktrigger: stonks
cryptotrigger: hodl
# Hostname header RapidAPI expects
rapidapiHost: yh-finance.p.rapidapi.com

View File

@ -1,6 +1,6 @@
maubot: 0.1.0
id: org.jobmachine.tickerbot
version: 0.0.5
version: 0.0.6
license: MIT
modules:
- tickerbot

View File

@ -15,6 +15,7 @@ class Config(BaseProxyConfig):
helper.copy("coinapiioKey")
helper.copy("stocktrigger")
helper.copy("cryptotrigger")
helper.copy("rapidapiHost")
class TickerBot(Plugin):
async def start(self) -> None:
@ -39,10 +40,10 @@ class TickerBot(Plugin):
return None
tickerUpper = ticker.upper()
url = f"https://apidojo-yahoo-finance-v1.p.rapidapi.com/market/v2/get-quotes?symbols={tickerUpper}"
url = f'https://{self.config["rapidapiHost"]}/market/v2/get-quotes?symbols={tickerUpper}'
headers = {
'x-rapidapi-key': self.config["rapidapiKey"],
'x-rapidapi-host': "apidojo-yahoo-finance-v1.p.rapidapi.com"
'x-rapidapi-host': self.config["rapidapiHost"]
}
try: