From 8b409dc96bc9e4116e763808083db7b0e362e124 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Fri, 21 Jan 2022 09:03:28 -0800 Subject: [PATCH] Adding more collections to NFT and formatting --- app/bot.py | 2 ++ app/nft.py | 14 +++++++++++++- app/stock.py | 20 +++++++++++--------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/bot.py b/app/bot.py index 3f928fba..c8fe18f0 100755 --- a/app/bot.py +++ b/app/bot.py @@ -544,9 +544,11 @@ async def stock(ctx): msg = ctx.message.content if len(msg.split()) < 2: import help_methods + await ctx.send(help_methods.get_help_message("stock")) import stock + results = stock.parse_message(msg) for res in results: await ctx.send(embed=res) diff --git a/app/nft.py b/app/nft.py index 0d6b051a..fa1d9a06 100644 --- a/app/nft.py +++ b/app/nft.py @@ -3,7 +3,19 @@ import random def get_nft(): - url = "https://api.opensea.io/api/v1/bundles?limit=50&asset_contract_address=0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d" + + # To find the collection's address, you have to do a curl against the API + # curl -s --request GET --url https://api.opensea.io/api/v1/collection/ | | jq -r .[].primary_asset_contracts[].address + collections = [ + "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d", + "0xbd3531da5cf5857e7cfaa92426877b022e612cf8", + "0x54a79ab6f5210fcb2c5fc914271a865003f15576", + "0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb", + ] + url = ( + "https://api.opensea.io/api/v1/bundles?limit=50&asset_contract_address=%s" + % random.choice(collections) + ) x = requests.get(url).json()["bundles"] return random.choice(x)["assets"][0]["image_url"] diff --git a/app/stock.py b/app/stock.py index fce1058e..bf17eba9 100755 --- a/app/stock.py +++ b/app/stock.py @@ -8,11 +8,11 @@ def parse_message(msg): verbose = False embeds = [] bad_tickers = [] - if set(['-v', '--verbose']) & set(split_msg): + if set(["-v", "--verbose"]) & set(split_msg): verbose = True for s in split_msg[1:]: # Skip flags - if s[0] != '-': + if s[0] != "-": try: embeds.append(get_stock(s, verbose=verbose)) except: @@ -46,11 +46,12 @@ def _add_verbose_fields(embed, request): ) embed.add_field( name="Change since prev. close (as %)", - value="$%.2f (%s%%)" % (request["regularMarketChange"], request["regularMarketChangePercent"]), + value="$%.2f (%s%%)" + % (request["regularMarketChange"], request["regularMarketChangePercent"]), inline=False, ) - if 'bid' in request and 'ask' in request: + if "bid" in request and "ask" in request: embed.add_field( name="Current bid price", value="$%s" % request["bid"], inline=False ) @@ -67,12 +68,12 @@ def _add_verbose_fields(embed, request): name="Day's Range", value=request["regularMarketDayRange"], inline=False ) - if 'marketCap' in request: + if "marketCap" in request: embed.add_field( name="Market Cap", value="{:,}".format(request["marketCap"]), inline=False - ) + ) - if 'sharesOutstanding' in request: + if "sharesOutstanding" in request: embed.add_field( name="Shares Outstanding", value="{:,}".format(request["sharesOutstanding"]), @@ -97,7 +98,7 @@ def get_stock(share_name, verbose=False): ] if not response: - raise ValueError('Invalid symbol %s: empty response from Yahoo' % share_name) + raise ValueError("Invalid symbol %s: empty response from Yahoo" % share_name) request = response[0] @@ -124,7 +125,8 @@ def get_stock(share_name, verbose=False): ) embed.add_field( name="Change since day open (as %)", - value="$%.2f (%.7f%%)" % (current_change, current_change * 100 / request["regularMarketOpen"]), + value="$%.2f (%.7f%%)" + % (current_change, current_change * 100 / request["regularMarketOpen"]), inline=False, )