<commit_before>import { StockPrice } from "../models/stockPrice";

import * as yql from "yql";

/**
 * StocksService
 */
export class StocksService {
    public getCurrentStockPrices(symbols: string): Promise<StockPrice[]> {
        const promise = new Promise<StockPrice[]>((resolve, reject) => {
            yql("select * from yahoo.finance.quote where symbol in (@symbol)", {
                env: "store://datatables.org/alltableswithkeys",
            })
                .setParam("symbol", symbols)
                .exec((error, response) => {
                    if (error) {
                        reject(error.message);
                    }

                    const stocks: StockPrice[] = [];
                    response.query.results.quote.forEach((stock) => {
                        const price: StockPrice = {
                            change: +stock.Change,
                            date: new Date(),
                            price: stock.LastTradePriceOnly,
                            symbol: stock.Symbol,
                            // tslint:disable-next-line:object-literal-sort-keys
                            name: stock.Name,
                        };

                        stocks.push(price);
                    });


                    resolve(stocks);
                });

        });

        return promise;
    }
}<commit_msg>fix for getting one stock from yahoo<commit_after>import { StockPrice } from "../models/stockPrice";

import * as yql from "yql";

/**
 * StocksService
 */
export class StocksService {
    public getCurrentStockPrices(symbols: string): Promise<StockPrice[]> {
        const promise = new Promise<StockPrice[]>((resolve, reject) => {
            yql("select * from yahoo.finance.quote where symbol in (@symbol)", {
                env: "store://datatables.org/alltableswithkeys",
            })
                .setParam("symbol", symbols)
                .exec((error, response) => {
                    if (error) {
                        reject(error.message);
                    }

                    const stocks: StockPrice[] = [];

                    // Response from Yahoo can an array or single object
                    if (response.query.results.quote instanceof Array) {
                        response.query.results.quote.forEach((stock) => {
                            const stockPrice = this.buildStockItem(stock);
                            stocks.push(stockPrice);
                        });

                    } else {
                        const stockPrice = this.buildStockItem(response.query.results.quote);
                        stocks.push(stockPrice);
                    }


                    resolve(stocks);
                });

        });

        return promise;
    }

    private buildStockItem(stock: any): StockPrice {
        const stockPrice: StockPrice = {
            change: +stock.Change,
            date: new Date(),
            price: stock.LastTradePriceOnly,
            symbol: stock.Symbol,
            // tslint:disable-next-line:object-literal-sort-keys
            name: stock.Name,
        };

        return stockPrice;

    }
}
{'fraction_non_alphanumeric': 0.10883280757097792, 'fraction_numerical': 0.0, 'mean_word_length': 1.2878787878787878, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '5699204', 'n_tokens_mistral': 790, 'n_tokens_neox': 734, 'n_words': 155}