-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathysar.xml
60 lines (57 loc) · 1.82 KB
/
ysar.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
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Sheridan C. Rawlins</author>
<sampleQuery>select * from {table} where host="www.yahoo.com"</sampleQuery>
</meta>
<bindings>
<select itemPath="ysar.line" produces="XML">
<urls>
<url>http://{host}/ysar</url>
</urls>
<inputs>
<key id="host" type="xs:string" paramType="path" required="true"/>
<key id="interval" type="xs:number" paramType="query"/>
</inputs>
<execute><![CDATA[
var fetch = y.query('select * from html where url=@url and xpath="//pre"', {url : request.url});
var ysar = fetch.results.pre;
var ysarXML = <></>;
var headerLines = 0;
var headers = [];
for each (var line in ysar.split("\n")) {
var isHeader = !line.match(/^\d/);
var foundHeader = false;
var vals = <></>;
var havevals = false;
var headerIndex = 0;
for each (var val in line.replace(/\s+/g," ").split(" ")) {
if ( val.match(/\S/) ) {
if ( isHeader ) {
foundHeader = true;
if ( headerLines < 2 ) {
if ( ! headers[headerIndex] ) {
headers[headerIndex] = [];
}
headers[headerIndex++].push(val);
}
} else {
vals += <val id={headers[headerIndex++].join(" ")}>{val}</val>;
havevals = true;
}
} else if ( isHeader ) {
++headerIndex;
}
}
if ( foundHeader ) {
++headerLines;
} else {
if ( havevals ) {
ysarXML += <line>{vals}</line>;
}
}
}
response.object = <ysar><url>{request.url}</url>{ysarXML}</ysar>;
]]></execute>
</select>
</bindings>
</table>