-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyql-exchange-rate.xml
35 lines (34 loc) · 1.62 KB
/
yql-exchange-rate.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
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Kaushal Chandrashekar</author>
<description>
Retrieves the exchange rate for the Indian Rupee from the DBS bank, Singapore's website. This first version is tightly coupled to the layout of the page.
Only works for INR at the moment.
</description>
<sampleQuery>
select * from {table} where currency='INR'
</sampleQuery>
</meta>
<bindings>
<select itemPath="rates.rate" produces="XML">
<inputs>
<key id="currency" type="xs:string" paramType="variable" required="true"/>
</inputs>
<execute>
<![CDATA[
var pairs = [];
for each (var p in pair.toString().replace(/\s+/g,'').split(','))
pairs.push(p.toUpperCase() + '=X');
var q = "select * from csv where url='http://download.finance.yahoo.com/d/quotes.csv?s="+ pairs.join(',') + "&f=snl1d1t1ab'" + " and columns='Symbol,Name,Rate,Date,Time,Ask,Bid'",
results = y.query(q), rates = <rates/>, rows=results.results.row; for each (var row in rows) { for each (var item in row.*) row[item.localName()]=item.text().toString().replace(/"/g, ''); var tag = row.Symbol.text().toString().substr(0,6); delete row.Symbol; rates.rate += <rate id={tag}>{row.*}</rate>; } response.object = rates;
var q = 'select content from html where url = "http://services.w3.org/tidy/tidy?docAddr=http%3A%2F%2Fwww.dbs.com.sg%2Fpersonal%2Frates-online%2Fforeign-currency-foreign-exchange.page" and xpath="//div[@class='
+ "'rates-table']/table/tr[4]/td[3]/p'";
results = y.query(q);
rates.rate = results.results.p;
response.object = rates;
]]>
</execute>
</select>
</bindings>
</table>
<!-- dt1.yql.gq1.yahoo.com Fri Dec 26 16:20:17 UTC 2014 -->