diff --git a/tickerbot.py b/tickerbot.py index c3b61bf..569b790 100644 --- a/tickerbot.py +++ b/tickerbot.py @@ -120,15 +120,20 @@ def get_sub_index_details(subindex_name): "% change": tds[6].text, "Turnover": tds[7].text, } + else: + return None return sub_index_details @client.command() async def subidx(ctx, *, subindex_name: str): sub_index_details = get_sub_index_details(subindex_name) - o = float(sub_index_details["Open"].replace(",", "")) - h = float(sub_index_details["High"].replace(",", "")) - c = float(sub_index_details["close"].replace(",", "")) + if sub_index_details==None: + await ctx.reply(f"The particular subindex:{subindex_name} doesn't exist or there might be a typo.π€\nPlease use `!helpnepse` to see the correct format! π") + return + o = round(float(sub_index_details["Open"].replace(",", "")),2) + h = round(float(sub_index_details["High"].replace(",", "")),2) + c = round(float(sub_index_details["close"].replace(",", "")),2) if o > c or o > h or o > c: embedcolor = discord.Color.red() else: @@ -174,8 +179,9 @@ async def subidx(ctx, *, subindex_name: str): embed.set_footer(text=f"As of: {last_mktsum}") await ctx.reply(embed=embed) - def get_stock_details(stock_name): + # if stock_name.upper()=="NEPSE": + # return None response = requests.get("https://www.sharesansar.com/live-trading") response2 = requests.get(f"https://www.sharesansar.com/company/{stock_name}") @@ -310,6 +316,9 @@ async def mktsum(ctx): @client.command() async def stonk(ctx, *, stock_name: str): + if stock_name.upper() == "NEPSE": + await ctx.reply("π For details on NEPSE, use `!index` or use `!mktsum` to get the market summary. π") + return stock_details = get_stock_details(stock_name) Embedcolor = discord.Color.default() ud_emoji = "" @@ -322,8 +331,8 @@ async def stonk(ctx, *, stock_name: str): company_name = extract_stock_name(stock_details["Company fullform"]) try: - last_traded_price = float(stock_details["Last Traded Price"].replace(",", "")) - prev_closing = float(stock_details["Prev.Closing"].replace(",", "")) + last_traded_price = round(float(stock_details["Last Traded Price"].replace(",", "")),2) + prev_closing = round(float(stock_details["Prev.Closing"].replace(",", "")),2) if last_traded_price > prev_closing: ud_emoji = "πΌ" @@ -489,7 +498,7 @@ def get_stock_price(stock_name): for row in stock_rows: row_data = row.find_all('td') # All