Stocks plugin for sopel

Thu, Oct 14, 2021 One-minute read

Good ol' irc is the best way to keep in contact with my friends, since ‘98 or around. We use sopel for some stuff, for example, to track all the stocks we own.

This is a simple stocks plugin for sopel.

import sopel
import requests

def stocks(bot,trigger):
        url = ""
        querystring = {"symbols":}
        headers = {'x-api-key': "FAKE_API_KEY"}
            response = requests.request("GET", url, headers=headers, params=querystring)
            stock = response.json()['quoteResponse']['result'][0]
        except requests.exceptions.RequestException as e:
            return bot.say("An error ocurred")
        return bot.say("Please use a valid symbol")

    change = '{0:.2f}'.format(float(stock['regularMarketChange']))
    percent = '{0:.2f}'.format(float(stock['regularMarketChangePercent']))

    return bot.say("{0}: {1} ({2}/{3})".format(stock['longName'], stock['regularMarketPrice'],"\x0304"+change+"\x0F" if float(change) < 0 else "\x0303"+change+"\x0F","\x0304"+percent+"%\x0F" if float(percent) < 0 else "\x0303+"+percent+"%\x0F",str(stock['regularMarketOpen'])))