feat: add github repo lookup command

This commit is contained in:
2021-07-29 12:58:47 -04:00
parent 5b0e8d3bee
commit a9985f4b4c
4 changed files with 60 additions and 19 deletions

View File

@@ -1,4 +1,5 @@
import os
from typing import List
import requests
import json
from discord.ext import commands
@@ -6,13 +7,12 @@ from discord.ext import commands
class Finance(commands.Cog):
"""Commands to query stock and crypto prices."""
@commands.command(usage="[tickers]")
async def stock(self, ctx, *tickers):
"""
Get prices for the given stock tickers. Will default tickers to AAPL, GOOG, MSFT and AMZN if none provided.
"""
@commands.command(usage="<tickers>")
async def stock(self, ctx, *tickers: List[str]) -> None:
"""Get prices for the given stock tickers. Will default tickers to AAPL, GOOG, MSFT and AMZN if none provided."""
ALPHAVANTAGE_API_KEY = os.getenv('ALPHAVANTAGE_API_KEY')
# default tickers
if len(tickers) == 0:
tickers = ["AAPL", "GOOG", "MSFT", "AMZN"]
@@ -22,7 +22,7 @@ class Finance(commands.Cog):
# make the call for stock prices
for ticker in tickers:
http_response = requests.get(f'https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol={ticker}&apikey={ALPHAVANTAGE_API_KEY}')
http_response = requests.get(f"https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol={ticker}&apikey={ALPHAVANTAGE_API_KEY}")
stock_data = json.loads(http_response.text)
# check if stock exists
@@ -30,7 +30,7 @@ class Finance(commands.Cog):
continue
# get the stock price
stock_price = stock_data['Global Quote']['05. price']
stock_price = stock_data["Global Quote"]["05. price"]
msg_response += f'**{ticker}**: ${round(float(stock_price), 2)}\n'
stock_found = True
@@ -41,12 +41,10 @@ class Finance(commands.Cog):
await ctx.send(msg_response)
@commands.command(usage="[tickers]")
async def crypto(self, ctx, *tickers):
"""
Get prices for the given crypto tickers. Will default tickers to BTC, ETH and LTC if none provided.
"""
LUNAR_CRUSH_API_KEY = os.getenv('LUNAR_CRUSH_API_KEY')
@commands.command(usage="<tickers>")
async def crypto(self, ctx, *tickers: List[str]) -> None:
"""Get prices for the given crypto tickers. Will default tickers to BTC, ETH and LTC if none provided."""
LUNAR_CRUSH_API_KEY = os.getenv("LUNAR_CRUSH_API_KEY")
# default tickers
if len(tickers) == 0: