loujr / miketysonbot

A Discord Bot Nicknamed Mike Tyson
4 stars 0 forks source link

stonks feature #4

Closed loujr closed 1 year ago

loujr commented 1 year ago

Adding the ability to type .stonk and receive an output -> previous stock app uses apidojo-yahoo-finance-v1.p.rapidapi.com

Found this interesting logic here:

https://stackoverflow.com/questions/50614682/how-do-i-add-arguments-to-a-discord-py-command

@bot.command(pass_context=True)
async def weather(ctx, index: int):
    weather = Weather(unit=Unit.CELSIUS)
    location = weather.lookup_by_location('toronto')
    forecasts = location.forecast

    embed = (discord.Embed(title="-=-__THE WEATHER__-=-", color=0x15dbc7))
    embed.add_field(name="Clouds", value=forecasts[index].text, inline=False) 
    embed.add_field(name="Date", value=forecasts[index].date, inline=False)
    embed.add_field(name="High", value=forecasts[index].high, inline=False)
    embed.add_field(name="Low", value=forecasts[index].low, inline=False)
    await bot.say(embed=embed)
loujr commented 1 year ago

Previous stock app

#!/usr/bin/python3

import requests
import json

url = "https://apidojo-yahoo-finance-v1.p.rapidapi.com/market/v2/get-quotes"

symbol = input('Please enter a ticker for a us company: ' )

querystring = {"region":"US","symbols":symbol}

headers = {
    'x-rapidapi-key': "<TOKEN>",
    'x-rapidapi-host': "apidojo-yahoo-finance-v1.p.rapidapi.com"
    }

response = requests.get(url,headers=headers,params=querystring)

##quoteresponse { 'result': [{your_data_points]]

data = response.json()
result = data['quoteResponse']['result'][0]

#values that we are interested in
name = result['longName']
ticker = result['symbol']
current_market_price = result['regularMarketPrice']
market_high = result['regularMarketDayHigh']
market_low = result['regularMarketDayLow']
market_cap = result['marketCap']
volume = result['regularMarketVolume']

print('Company Name: ', name)
print('Ticker: ', ticker)
print('Current Market Price: ', current_market_price)
print('Market High: ', market_high)
print('Market Low: ', market_low)
print('Market Cap:', market_cap)
print('Volume: ', volume)

print("Stonks Never Go Down")  
loujr commented 1 year ago

Added feature in PR