from typing import List
import glob


def get_stock_symbols(market: str) -> List[str]:
    """
    Read stock symbols from internal file

    Parameters
    ----------
    market: str
        The stock market (NASDAQ | NYSE)
    
    Returns
    -------
    List
        A list of symbols for the given market
    """

    sym = str()
    syms = list()
    sym_files = list()

    # glob the sym files and get all the markets
    sym_files = glob.glob('./stock_symbols/sym_*.txt')
    for sym in sym_files:
        syms.append(sym.strip().replace('.txt','').split('_')[2])
    if market.upper() not in syms:
        print(syms)
        raise Exception

    # read out symbols for given market
    # market file name should be sym_<MARKET_NAME> located at ./stock_symbols/
    symbols = list()
    with open('./stock_symbols/sym_' + market.upper() + '.txt') as market_file:
        for line in market_file:
            symbols.append(line.strip())
    return symbols