This repository has been archived by the owner on Dec 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
yahoo.finance.stocks.xml
144 lines (128 loc) · 4.01 KB
/
yahoo.finance.stocks.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?xml version="1.0" encoding="UTF-8" ?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Tom Powers</author>
<description>Yahoo Finance Stock Summary Information</description>
<sampleQuery>select * from {table} where symbol="yhoo"</sampleQuery>
</meta>
<bindings>
<select itemPath="" produces="XML">
<urls>
<url></url>
</urls>
<inputs>
<key id='symbol' type='xs:string' paramType='variable' required='true' />
</inputs>
<execute><![CDATA[
// pad string with leading char
String.prototype.pad = function (padchar, padlen) {
s = this
while (s.length < padlen) {
s = padchar + s;
}
return s;
}
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);
}
function getQuoteInfo() {
// Get company name & market from Yahoo Quotes Summary page
var results = quoteQuery.results;
elements = results.*.length();
if (elements == 0)
return false;
var companyName = [email protected]().trim();
var market = results.span.text().toString().trim();
stock.appendChild(<CompanyName>{companyName}</CompanyName>);
stock.appendChild(<Market>{market}</Market>);
return true;
}
function getHistoricalPrice() {
// Get the Historical Price Range
var results = historicalQuery.results;
elements = results.*.length();
if (elements < 6)
return false;
startMonth = String(parseInt(results.option[0].@value)+1).pad("0", 2);
startDay = results.input[0][email protected]().pad("0", 2);
startYear = results.input[1][email protected]();
endMonth = String(parseInt(results.option[1].@value)+1).pad("0", 2);
endDay = results.input[2][email protected]().pad("0", 2);
endYear = results.input[3][email protected]();
startDate = startYear + "-" + startMonth + "-" + startDay;
endDate = endYear + "-" + endMonth + "-" + endDay;
stock.appendChild(<start>{startDate}</start>);
stock.appendChild(<end>{endDate}</end>);
return true;
}
function getProfileInfo() {
// Get the Sector, Industry, Full Time Employees from Profile page
var results = profileQuery.results;
elements = results.*.length();
if (elements == 0)
return false;
for each (var tr in results.tr){
//Remove trailing colon, and strip whitespace
var property = tr.td[0].text()
.toString().slice(0, -1)
.replace(/\s+/g, "");
switch (property.toLowerCase()) {
case 'indexmembership':
continue;
break;
case 'fulltimeemployees':
//Strip commas
value = tr.td[1].text().toString().replace(/,/g, "");
break;
default:
//Convert whitespace to single space
if (tr.td[1].a) {
value = tr.td[1].a.text().toString().replace(/\s+/g, " ");
} else {
value = tr.td[1].text().toString().replace(/\s+/g, " ");
}
break;
}
stock.appendChild(<{property}>{value}</{property}>);
}
return true;
}
// Queue the queries
var url = "http://finance.yahoo.com/q/pr?s="+symbol;
var profileQuery = y.query(
"select * from html " +
"where url=@url and " +
"xpath='//table[@class=\"yfnc_datamodoutline1\"]/tbody/tr/td/table/tbody/tr' " +
"limit 4",
{url:url});
var url = "http://finance.yahoo.com/q?s="+symbol;
var quoteQuery = y.query(
"select * from html " +
"where url=@url and compat='html5' and " +
"xpath='" +
"//meta[@property=\"og:title\"] | " +
"//span[@class=\"rtq_exch\"]'" ,
{url:url});
var url = "http://finance.yahoo.com/q/hp?s="+symbol;
var historicalQuery = y.query(
"select * from html " +
"where url=@url and " +
"xpath='" +
"//option[@selected=\"selected\"] | " +
"//input[@maxlength=\"2\"] | " +
"//input[@maxlength=\"4\"]'",
{url:url});
var stock = <stock symbol={symbol}></stock>;
getQuoteInfo();
getHistoricalPrice();
getProfileInfo();
response.object = stock
]]></execute>
</select>
</bindings>
</table>
<!-- dt1.yql.bf1.yahoo.com Mon Nov 24 22:11:55 UTC 2014 -->