forked from yql/yql-tables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeout.london.search.xml
149 lines (132 loc) · 4.7 KB
/
timeout.london.search.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
145
146
147
148
149
<?xml version="1.0" encoding="UTF-8"?>
<!--
Document : timeout.london.search.xml
Created on : March 13, 2010, 12:03 PM
Author : Rob Young <rob@roryoung.co.uk>
Description:
An Open Data Table for Time Out London's search page.
-->
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Rob Young</author>
<sampleQuery>USE "http://www.roryoung.co.uk/timeout.london.search.xml" as timeout.london.search; SELECT * FROM timeout.london.search;</sampleQuery>
<documentationURL></documentationURL>
</meta>
<bindings>
<select itemPath="" produces="JSON">
<urls>
<url>http://www.timeout.com/london/search/</url>
</urls>
<paging model="page">
<start default="1" id="page"/>
<pagesize max="200" id="count"/>
<total default="20"/>
</paging>
<inputs>
<key id="tag" type="xs:string" paramType="variable"/>
<key id="tag_id" type="xs:string" paramType="variable"/>
<key id="date" type="xs:string" paramType="variable"/>
<key id="type" type="xs:string" paramType="variable"/>
<key id="area" type="xs:string" paramType="variable"/>
<key id="postcode" type="xs:string" paramType="variable"/>
<key id="keyword" type="xs:string" paramType="variable"/>
</inputs>
<execute><![CDATA[
function join(key, value) {
return key + '=' + value;
}
function each(map, func) {
var out = [];
for (key in map) {
out.push(func(key, map[key]));
}
return out;
}
tag_map = {
"Alternative Nightlife": 362,
"Around Town": 2,
"Art": 84,
"Bars": 300002,
"Books & Poetry": 186,
"Cabaret": 411,
"Classical Music": 190,
"Clubs": 39,
"Comedy": 351,
"Dance": 197,
"Festivals": 384,
"Film": 144,
"Gay & Lesbian": 79,
"Hotels": 4308,
"Kids": 129,
"Museums & Attractions": 36,
"Music": 72,
"Restaurants": 4256,
"Shopping": 412,
"Theatre": 352
};
var params = [];
if (tag != undefined) {
params['tag_id'] = tag_map[tag];
}
if (tag_id != undefined) {
params['tag_id'] = tag_id;
}
if (date != undefined) {
params['date'] = date;
}
if (type != undefined) {
params['type'] = type;
}
if (area != undefined) {
params['area'] = area;
}
if (postcode != undefined) {
params['postcode'] = postcode;
}
if (keyword != undefined) {
params['keyword'] = keyword;
}
params['pageNumber'] = page;
params['pageSize'] = count;
var base_url = "http://www.timeout.com/london/search/";
var query = each(params, join).join('&');
var url = base_url + '?' + query;
var xpath = '//div[@id="result-container"]/div[contains(@class, "result")]/div[@class="left-column"]';
y.log("URL: " + url);
var query = y.query("SELECT * FROM html WHERE url=@url AND xpath=@xpath", {url:url, xpath:xpath});
var results = <results></results>;
for each(var result in query.results.div) {
var my_result = <result/>
my_result.appendChild(<title>{result.h2.a.text()}</title>);
my_result.link.@href = result.h2.a.@href;
var review = result.*.(@["class"] == "review-container");
var details = result.*.(@["class"] == "details");
var flags = result.*.(@["class"] == "flags-container");
var date = review..strong.text();
if (date.length() == 0) {
date = details.span.span.text();
}
my_result.appendChild(<date>{date}</date>);
my_result.appendChild(<summary>{review.p.(@["class"] == "review").text()}</summary>);
if (flags.h4.span.length() != 0) {
for (var i in flags.h4.span) {
my_result.appendChild(<category>{flags.h4.span[i].text()}</category>);
}
} else {
my_result.appendChild(<category>{flags.h4.text()}</category>);
}
for (var i in flags..span) {
var c = flags..span[i].@["class"];
if (c.length() && c.match(/^flag /)) {
if (flags..span[i].text().length()) {
my_result.appendChild(<tag>{flags..span[i].text()}</tag>);
}
}
}
results.appendChild(my_result);
}
response.object = results;
]]></execute>
</select>
</bindings>
</table>