<commit_before>var request = require( 'request' );
var util = require('util');

var SYMBOL_API_FMT = 'https://query.yahooapis.com/v1/public/yql?q=select%%20*%%20from%%20yahoo.finance.quotes%%20where%%20symbol%%20in%%20(%%22%s%%22)&format=json&env=store%%3A%%2F%%2Fdatatables.org%%2Falltableswithkeys&callback=';
var RESULT_FMT = '%s (%s): %s (%s)';

function get_sym(symbol, cb) {
	/* cb should accept e, r { value, delta, % delta } */
	var req = util.format(SYMBOL_API_FMT, symbol);

	request.get( req, function (e, r, b) {
		if ( e ) {
			cb (e, r, b);
			return 'problem fetching data';
		}
		if ( r.statusCode !== 200 ) {
			cb ('bad status code', r, b);
			return 'problem fetching data (' + r.statusCode + ')';
		}

		var data = JSON.parse(b);
		var symboldata = data.query.results.quote;

		cb (e, symboldata);
	} );
}

module.exports = {
	commands: {
		yhoo: {
			help: 'Displays information about a ticker symbol via yahoo',
			usage: [ 'symbol' ],
			command: function ( bot, msg ) {
				get_sym( msg.args.symbol, function( e, r ) {
					if ( e ) {
						bot.say( msg.to, 'Problem fetching symbol: ' + e );
					}

					bot.say( msg.to, util.format( RESULT_FMT, r.symbol, r.Name, r.Ask, r.Change_PercentChange ) );
				} );
			}
		}
	}
};<commit_msg>Handle nonsensical symbol, display currency<commit_after>var request = require( 'request' );
var util = require('util');

var SYMBOL_API_FMT = 'https://query.yahooapis.com/v1/public/yql?q=select%%20*%%20from%%20yahoo.finance.quotes%%20where%%20symbol%%20in%%20(%%22%s%%22)&format=json&env=store%%3A%%2F%%2Fdatatables.org%%2Falltableswithkeys&callback=';
var RESULT_FMT = '%s (%s): %s %s (%s)';

function get_sym(symbol, cb) {
	/* cb should accept e, r { value, delta, % delta } */
	var req = util.format(SYMBOL_API_FMT, symbol);

	request.get( req, function (e, r, b) {
		if ( e ) {
			cb (e, r, b);
			return 'problem fetching data';
		}
		if ( r.statusCode !== 200 ) {
			cb ('bad status code', r, b);
			return 'problem fetching data (' + r.statusCode + ')';
		}

		var data = JSON.parse(b);
		var symboldata = data.query.results.quote;

		cb (e, symboldata);
	} );
}

module.exports = {
	commands: {
		yhoo: {
			help: 'Displays information about a ticker symbol via yahoo',
			usage: [ 'symbol' ],
			command: function ( bot, msg ) {
				get_sym( msg.args.symbol, function( e, r ) {
					if ( e ) {
						bot.say( msg.to, 'Problem fetching symbol: ' + e );
					} else if ( r.Currency ) { // probably always exists
						bot.say( msg.to, util.format( RESULT_FMT, r.symbol, r.Name, r.Ask, r.Currency, r.Change_PercentChange ) );
					} else {
						bot.say( msg.to, 'Problem parsing symbol' );
					}
				} );
			}
		}
	}
};
{'fraction_non_alphanumeric': 0.18117559523809523, 'fraction_numerical': 0.019345238095238096, 'mean_word_length': 3.4009819967266774, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '5785886', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1013, 'n_words': 236}