Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated yahoo.finance.keystatistics.xml #1

Merged
merged 1 commit into from
Nov 23, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 11 additions & 61 deletions yahoo/finance/yahoo.finance.keystats.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>
Ryan Hoium
Original: Ryan Hoium
Updated by: James Dyer
</author>
<description>
Yahoo Finance - Key Statistics by Stock Symbol
Expand All @@ -22,75 +23,30 @@
</inputs>
<execute>
<![CDATA[
//UTILITY: pad string with leading char
String.prototype.pad = function ( padchar, padlen )
{
s = this

while (s.length < padlen)
{
s = padchar + s;
}

return s;
}

//UTILITY: convert string to INTEGER
String.prototype.toInt = function ()
{
// remove leading 0's because otherwise
// str can be interpreted as Octal
var str = this.replace( /^0+/, '' );

// also the thousands comma was cousing trouble
str = str.trim()
str = str.replace( /\,/g, '' );

// replace M with 6 ZEROs, B with 9 ZEROs (UPDATE THIS - ACCOUNT FOR DECIMAL!!
//str = str.replace(/M/g,'000000');
//str = str.replace(/B/g,'000000000');

return parseInt( str );
}
//UTILITY: trim whitespace
String.prototype.trim = function ()
{
var str = this.replace( /^\s\s*/, "" ),
ws = /\s/,
i = str.length;
while ( ws.test( str.charAt( --i ) ) );
return str.slice( 0, i + 1 );
}

// Setup Query from finance.yahoo.com
var url="http://finance.yahoo.com/q/ks?s=" + symbol;
var restquery = y.rest( url );
var rawresult = restquery.accept( "text/html" ).get().response;
var keystatsquery = y.xpath(
rawresult,
"//table[@class='yfnc_datamodoutline1']/tr/td/table/tr" +
"/td[@class='yfnc_tabledata1' or @class='yfnc_tablehead1']"
);

var xpath = "//table[@class='yfnc_datamodoutline1']/tbody/tr/td/table/tbody/tr/td[@class='yfnc_tabledata1' or @class='yfnc_tablehead1']";
var query = y.query("select * from html where url=@url and compat='html5' and xpath=@xpath", {url:url, xpath:xpath});
var keystatsquery = query.results;

// Process Results
var statsdata = <stats symbol={symbol}></stats>;
if ( keystatsquery.*.length() != 0 )
if ( keystatsquery.td.length() !== 0 )
{

var i = 0;
while ( i < keystatsquery.length())
while ( i < keystatsquery.td.length())
{
// Setup to Process Two 'td' Elements at a Time - Name and Value Pairs
var td_param_name = keystatsquery[i];
var td_value = keystatsquery[i+1];
var td_param_name = keystatsquery.td[i];
var td_value = keystatsquery.td[i+1];
var param_name = "";
var attr = "";
var value = "";
i = i + 2;

// Process Parameter Name and any Associated Attributes (Timeframe, Stock Split Info)
param_name = td_param_name.p.text().toString();
param_name = td_param_name.text().toString();
param_name = String(param_name.replace(/:/g,""));
attr = String(param_name.match(/\(.*\)/));
attr = String(attr.trim());
Expand All @@ -105,7 +61,7 @@
param_name = param_name.trim();

// Process Value Information
value = td_value.p.text().toString();
value = td_value.text().toString();
// Catch When it is Span Tag instead of P tag
if( value == false){
value = td_value.span.text().toString();
Expand All @@ -123,12 +79,6 @@
}
// Return statsdata strucuture
response.object = statsdata;






]]>
</execute>
</select>
Expand Down