<commit_before>import requests
from plugin import plugin
from colorama import Fore
import re


@plugin('stock')
class Stock:

    def __call__(self, jarvis, s):
        if not s:
            self.usage(jarvis)
        else:
            ps = s.split()
            if ps[0] == 'getid':
                ps.pop(0)
                if ps:
                    name = ' '.join(ps)
                else:
                    name = jarvis.input("Enter the name of the stock: ")
                self.get_stock_id(jarvis, name)
            elif ps[0] == 'help':
                self.usage(jarvis)
            elif ps[0] == 'profile':
                if(len(ps) != 2):
                    jarvis.say("You forgot to mention the symbol", Fore.RED)
                else:
                    symbol = ps[1]
                    self.get_profile(jarvis, symbol)
            elif ps[0] == 'fstatement':
                if(len(ps) != 2):
                    jarvis.say("You forgot to mention the symbol", Fore.RED)
                else:
                    symbol = ps[1]
                    self.get_financial_stmt(jarvis, symbol)
            elif ps[0] == 'gainers':
                self.get_gainers(jarvis)
            elif ps[0] == 'losers':
                self.get_losers(jarvis)
            # anything else is treated as a stock symbol
            else:
                self.get_stock_data(jarvis, s)

    def usage(self, jarvis):
        ''' Print the usage for stock command '''
        jarvis.say("stock <stock_id>\t : Get details of stock identified by <stock_id>(one id at a time)", Fore.GREEN)
        jarvis.say("stock getid\t\t : Search stock id", Fore.GREEN)
        jarvis.say("stock profile <stock_id>\t : Get company profile", Fore.GREEN)
        jarvis.say("stock fstatement <stock_id>\t : Get latest ANNUAL finincial statement of the company", Fore.GREEN)
        jarvis.say("stock gainers\t\t : Most gainers in NYSE", Fore.GREEN)
        jarvis.say("stock losers\t\t : Most losers in NYSE", Fore.GREEN)
        jarvis.say("stock help\t\t : Prints help", Fore.GREEN)
        jarvis.say("*** AVAILABLE ONLY FOR US EQUITIES ***", Fore.GREEN)

    def get_stock_data(self, jarvis, quote):
        ''' Given a stock symbol, get the real time price of the stock '''
        url = 'https://financialmodelingprep.com/api/v3/stock/real-time-price/' + quote
        resp = requests.get(url)

        if(resp.status_code == 200):
            data = resp.json()
            if('symbol' in data.keys()):
                jarvis.say("Symbol: " + str(data['symbol']), Fore.GREEN)
                jarvis.say("Price: " + str(data['price']), Fore.GREEN)
            elif('Error' in data.keys()):
                jarvis.say("Invalid stock symbol name", Fore.RED)
            else:
                jarvis.say("Error. Please retry")
        else:
            jarvis.say("Cannot find the name. Try again later\n", Fore.RED)

    def get_stock_id(self, jarvis, name):
        ''' Get the list of stock IDs given a company name or part of the company name '''
        url = 'https://financialmodelingprep.com/api/v3/company/stock/list'
        resp = requests.get(url)

        if(resp.status_code == 200):
            data = resp.json()
            found = False<commit_msg>Stock: Move help to docstring<commit_after>import requests
from plugin import plugin
from colorama import Fore
from inspect import cleandoc
import re


@plugin('stock')
class Stock:
    """
    stock <stock_id>            : Get details of stock identified by <stock_id>(one id at a time)
    stock getid                 : Search stock id
    stock profile <stock_id>    : Get company profile
    stock fstatement <stock_id> : Get latest ANNUAL finincial statement of the company
    stock gainers               : Most gainers in NYSE
    stock losers                : Most losers in NYSE
    stock help                  : Prints help
    *** AVAILABLE ONLY FOR US EQUITIES ***
    """

    def __call__(self, jarvis, s):
        if not s or 'help' in s:
            jarvis.say(cleandoc(self.__doc__), Fore.GREEN)
        else:
            ps = s.split()
            if ps[0] == 'getid':
                ps.pop(0)
                if ps:
                    name = ' '.join(ps)
                else:
                    name = jarvis.input("Enter the name of the stock: ")
                self.get_stock_id(jarvis, name)
            elif ps[0] == 'profile':
                if(len(ps) != 2):
                    jarvis.say("You forgot to mention the symbol", Fore.RED)
                else:
                    symbol = ps[1]
                    self.get_profile(jarvis, symbol)
            elif ps[0] == 'fstatement':
                if(len(ps) != 2):
                    jarvis.say("You forgot to mention the symbol", Fore.RED)
                else:
                    symbol = ps[1]
                    self.get_financial_stmt(jarvis, symbol)
            elif ps[0] == 'gainers':
                self.get_gainers(jarvis)
            elif ps[0] == 'losers':
                self.get_losers(jarvis)
            # anything else is treated as a stock symbol
            else:
                self.get_stock_data(jarvis, s)

    def get_stock_data(self, jarvis, quote):
        ''' Given a stock symbol, get the real time price of the stock '''
        url = 'https://financialmodelingprep.com/api/v3/stock/real-time-price/' + quote
        resp = requests.get(url)

        if(resp.status_code == 200):
            data = resp.json()
            if('symbol' in data.keys()):
                jarvis.say("Symbol: " + str(data['symbol']), Fore.GREEN)
                jarvis.say("Price: " + str(data['price']), Fore.GREEN)
            elif('Error' in data.keys()):
                jarvis.say("Invalid stock symbol name", Fore.RED)
            else:
                jarvis.say("Error. Please retry")
        else:
            jarvis.say("Cannot find the name. Try again later\n", Fore.RED)

    def get_stock_id(self, jarvis, name):
        ''' Get the list of stock IDs given a company name or part of the company name '''
        url = 'https://financialmodelingprep.com/api/v3/company/stock/list'
        resp = requests.get(url)

        if(resp.status_code == 200):
            data = resp.json()
            found = False
{'fraction_non_alphanumeric': 0.1143358316058045, 'fraction_numerical': 0.005900175410620316, 'mean_word_length': 1.6655333616659584, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1848873', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1773, 'n_words': 510}