Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/yql/yql-tables
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaaker committed Nov 22, 2010
2 parents b934def + 3758cac commit 6678949
Show file tree
Hide file tree
Showing 116 changed files with 4,680 additions and 448 deletions.
26 changes: 26 additions & 0 deletions batlas/batlas.distance.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd" https="false">
<meta>
<author>Daniel Pett</author>
<description>Search Pleiades for items within a set distance</description>
<sampleQuery description="Search within a lat/lon pt for radius 20km">select * from {table} where distance='20000' and lat="53.909994" and lon="-1.803595";</sampleQuery>
</meta>
<bindings>
<select itemPath="json.items" produces="JSON">
<urls>
<url>http://bacchus.atlantides.org/t/pleiades/distance?</url>
</urls>
<paging model="offset">
<start id="start" default="0" />
<pagesize id="count" max="20" />
<total default="20"/>
</paging>
<inputs>
<key id="lon" type="xs:string" paramType="query" required="true" />
<key id="lat" type="xs:string" paramType="query" required="true" />
<key id="radius" type="xs:string" paramType="query" required="true" />
<key id="strict" type="xs:boolean" paramType="query" required="false" />
</inputs>
</select>
</bindings>
</table>
27 changes: 27 additions & 0 deletions batlas/batlas.intersection.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd" https="false">
<meta>
<author>Daniel Pett</author>
<description>Search Pleiades for items within a set bounding box</description>
<sampleQuery description="Search for places within bounding box">select * from {table} where min_lon = "20" and min_lat = "30" and max_lon = "22" and max_lat = "32" and limit="1"</sampleQuery>
</meta>
<bindings>
<select itemPath="json.items" produces="JSON">
<urls>
<url>http://bacchus.atlantides.org/t/pleiades/intersection?bbox={min_lon},{min_lat},{max_lon},{max_lat}</url>
</urls>
<paging model="offset">
<start id="start" default="0" />
<pagesize id="count" max="20" />
<total default="20"/>
</paging>
<inputs>
<key id="min_lon" type="xs:string" paramType="path" required="true" />
<key id="min_lat" type="xs:string" paramType="path" required="true" />
<key id="max_lon" type="xs:string" paramType="path" required="true" />
<key id="max_lat" type="xs:string" paramType="path" required="true" />

</inputs>
</select>
</bindings>
</table>
27 changes: 27 additions & 0 deletions batlas/batlas.nearest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd" https="false">
<meta>
<author>Daniel Pett</author>
<description>Search Pleiades for items nearest to a bounding box</description>
<sampleQuery description="Search for nearest places to bounding box">select * from {table} where min_lon = "20" and min_lat = "30" and max_lon = "22" and max_lat = "32" and limit="1"</sampleQuery>
</meta>
<bindings>
<select itemPath="json.items" produces="JSON">
<urls>
<url>http://bacchus.atlantides.org/t/pleiades/nearest?bbox={min_lon},{min_lat},{max_lon},{max_lat}</url>
</urls>
<paging model="offset">
<start id="start" default="0" />
<pagesize id="count" max="20" />
<total default="20"/>
</paging>
<inputs>
<key id="min_lon" type="xs:string" paramType="path" required="true" />
<key id="min_lat" type="xs:string" paramType="path" required="true" />
<key id="max_lon" type="xs:string" paramType="path" required="true" />
<key id="max_lat" type="xs:string" paramType="path" required="true" />
<key id="limit" type="xs:boolean" paramType="query" required="false" />
</inputs>
</select>
</bindings>
</table>
4 changes: 2 additions & 2 deletions bbc/bbc.goodfood.seasonal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Rob Young</author>
<sampleQuery>USE "http://www.roryoung.co.uk/bbc.goodfood.seasonal.xml" as bbc.goodfood.seasonal; SELECT * FROM bbc.goodfood.seasonal;</sampleQuery>
<sampleQuery>SELECT * FROM bbc.goodfood.seasonal;</sampleQuery>
<documentationURL></documentationURL>
</meta>
<bindings>
Expand Down Expand Up @@ -84,4 +84,4 @@
]]></execute>
</select>
</bindings>
</table>
</table>
206 changes: 110 additions & 96 deletions bible/bible.bible.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<meta>
<author>Vic Mortelmans</author>
<description>The table contains the complete bible. Each passage is a record, identified by it's citation reference.</description>
<sampleQuery>select * from bible where language='en' and edition='king james' and book='Luke' and chapter=11 and passage=10</sampleQuery>
<sampleQuery>select * from bible.bible where language='en' and book='Luke' and chapter=11 and passage=10</sampleQuery>
<documentationURL>http://docs.google.com/View?id=ddq89pzk_155t6rwmkhp</documentationURL>
</meta>
<bindings>
Expand All @@ -12,63 +12,107 @@
<url></url>
</urls>
<inputs>
<key id="language" type="xs:string" paramType="variable" required="false" default="en"/>
<key id="language" type="xs:string" paramType="variable" required="false"/>
<key id="edition" type="xs:string" paramType="variable" required="false"/>
<key id="book" type="xs:string" paramType="variable" required="true"/>
<key id="chapter" type="xs:integer" paramType="variable" required="true"/>
<key id="passage" type="xs:integer" paramType="variable" required="true"/>
</inputs>
<execute><![CDATA[
if (!edition) {
var editionsquery = 'select edition from xml where url="http://github.com/vicmortelmans/yql-tables/raw/master/bible/editions.xml" and edition.language matches "(?i)$language" and edition.default="true"';
editionsquery = editionsquery.replace("$language",language);
var editions = y.query(editionsquery).results.editions;
if (editions.edition.length() < 1) {
var supported_languagesquery = 'select edition.language from xml where url="http://github.com/vicmortelmans/yql-tables/raw/master/bible/editions.xml" and edition.default="true"';
var supported_languages = y.query(supported_languagesquery).results.editions.edition.language;
var error_message = 'Language $language is not supported. Supported bible languages : $supported';
error_message = error_message.replace("$language",language);
error_message = error_message.replace("$supported",stringListValue(supported_languages));
y.log(error_message);
y.exit();
if (!edition && !language) {
language = "en";
}
var editionsquery = 'select edition from xml where url="http://github.com/vicmortelmans/BibleConfiguration/raw/master/editions.xml" and edition.input like "%$edition%" and edition.language matches "(?i)$language"';
editionsquery = editionsquery.replace("$language",language?language:'.*');
editionsquery = editionsquery.replace("$edition",edition?edition:'');
var editions = y.query(editionsquery).results.editions;
var edition;
if (editions.edition.length() < 1) {
var supported_editionsquery = 'select edition from xml where url="http://github.com/vicmortelmans/BibleConfiguration/raw/master/editions.xml"';
var supported_editions = y.query(supported_editionsquery).results.editions;
y.log('No bible edition found matching query parameters. Supported editions and languages:');
y.log(listEditions(supported_editions));
y.exit();
} else if (editions.edition.length() > 1) {
edition = editions.edition.(default_ == "true")[0];
if ( ! edition ) {
edition = editions.edition[0];
}
y.log('Multiple bible editions found matching query parameters: ');
y.log(listEditions(editions));
} else {
var editionsquery = 'select edition from xml where url="http://github.com/vicmortelmans/yql-tables/raw/master/bible/editions.xml" and edition.input matches "(?i)$edition"';
editionsquery = editionsquery.replace("$edition",edition);
var editions = y.query(editionsquery).results.editions;
if (editions.edition.length() < 1) {
var supported_editionsquery = 'select edition.input from xml where url="http://github.com/vicmortelmans/yql-tables/raw/master/bible/editions.xml" and edition.language matches "(?i)$language"';
supported_editionsquery = supported_editionsquery.replace("$language",language);
var supported_editions = y.query(supported_editionsquery).results.editions.edition.input;
var error_message = 'Edition $edition is not supported. Supported bible editions for language "$language": $supported';
error_message = error_message.replace("$edition",edition);
error_message = error_message.replace("$language",language);
error_message = error_message.replace("$supported",stringListValue(supported_editions));
if (supported_editions.length() < 1) {
var supported_editionsquery = 'select edition.input from xml where url="http://github.com/vicmortelmans/yql-tables/raw/master/bible/editions.xml"';
var supported_editions = y.query(supported_editionsquery).results.editions.edition.input;
error_message = 'Edition $edition is not supported. Supported bible editions: $supported';
error_message = error_message.replace("$edition",edition);
error_message = error_message.replace("$supported",stringListValue(supported_editions));
}
edition = editions.edition[0];
}
y.log('Using: ');
y.log(listEditions(<editions>{edition}</editions>));
if (edition.copyright.toString()) {
y.log('Copyright: ');
y.log(edition.copyright.toString());
}
//y.log(edition);
var booksquery = 'select book from xml where url="http://github.com/vicmortelmans/BibleConfiguration/raw/master/books.xml" and book.input matches "(?i)$book"';
booksquery = booksquery.replace("$book",book);
var books = y.query(booksquery).results.books;
if (books.book.length() < 1) {
var error_message = '$book is not a bible book. Common bible book abbreviations : $supported';
error_message = error_message.replace("$book",book);
error_message = error_message.replace("$supported","http://biblewiki.net/books/index");
y.log(error_message);
y.exit();
}
}
var service_switch = editions.edition[0].service.toString();
var language_switch = editions.edition[0].language.toString();
var edition_name = editions.edition[0].input.(@type=="name").toString();
switch (service_switch) {
case "biblija_net":
y.log("using " + edition_name);
response.object = biblija_net();
break;
default:
y.log("Internal error - service switch : " + service_switch);
y.exit();
book = books.book[0];
//y.log(book);
var servicesquery = 'select service from xml where url="http://github.com/vicmortelmans/BibleConfiguration/raw/master/services.xml" and service.name matches "(?i)$service"';
servicesquery = servicesquery.replace("$service",edition.code.(@default_ == "true").@service.toString());
var services = y.query(servicesquery).results.services;
if (services.service.length() < 1) {
var error_message = 'Internal error';
y.log(error_message);
y.exit();
}
service = services.service[0];
//y.log(service);
var bookcode = book.code.(@service == service.name.toString()).toString();
var editioncode = edition.code.(@service == service.name.toString()).toString();
var url = '';
var finalquery = '';
for each (var step in service.step) {
if (step.@nr < service.step.length()) {
if (step.@yql.toString() == "true") { // yql query
var query = step.toString();
query = query.replace(/\$book/g,bookcode);
query = query.replace(/\$edition/g,editioncode);
query = query.replace(/\$chapter/g,chapter);
query = query.replace(/\$passage/g,passage);
query = query.replace(/\$url/g,url);
var rest = 'http://query.yahooapis.com/v1/public/yql?q=$query&diagnostics=true';
rest = rest.replace("$query",escape(query));
url = rest;
//y.log(url);
} else { // rest call
var rest = step.toString();
rest = rest.replace(/\$book/g,escape(bookcode));
rest = rest.replace(/\$edition/g,escape(editioncode));
rest = rest.replace(/\$chapter/g,escape(chapter));
rest = rest.replace(/\$passage/g,escape(passage));
rest = rest.replace(/\$url/g,escape(url));
url = rest;
//y.log(url);
}
} else { // last step is always yql query
finalquery = step.toString();
finalquery = finalquery.replace(/\$book/g,bookcode);
finalquery = finalquery.replace(/\$edition/g,editioncode);
finalquery = finalquery.replace(/\$chapter/g,chapter);
finalquery = finalquery.replace(/\$passage/g,passage);
finalquery = finalquery.replace(/\$url/g,url);
//y.log(finalquery);
}
}
var queryoutput = y.query(finalquery).results;
response.object = <passage>{stringListValue(queryoutput)}</passage>;
function stringValue(node) {
var value = "";
if (node.hasSimpleContent()) {
Expand All @@ -87,64 +131,34 @@
value = node.toString();
} else {
for each (var c in node.children()) {
value += stringValue(c) + ", ";
value += stringValue(c) + " ";
}
value = value.replace(/, $/,'');
}
return value;
}
function biblija_net() {
var edition_api = editions.edition[0].biblija_net.toString();
var booksquery = 'select book.biblija_net from xml where url="http://github.com/vicmortelmans/yql-tables/raw/master/bible/books.xml" and book.input matches "(?i)$book"';
booksquery = booksquery.replace("$book",book);
var books = y.query(booksquery).results.books;
if (books.book.length() < 1) {
var error_message = '$book is not a bible book. Common bible book abbreviations : $supported';
error_message = error_message.replace("$book",book);
error_message = error_message.replace("$supported","http://biblewiki.net/books/index");
y.log(error_message);
y.exit();
}
var book_api = books.book[0].biblija_net.toString();
var url = "http://www.biblija.net/biblija.cgi?Bible=Bible&m=$citation&compact=1&$edition_api=1&pos=0&set=1&l=en";
url = url.replace("$citation",escape(book_api + " " + chapter + ":" + passage));
url = url.replace("$edition_api",escape(edition_api));
var yql = "select * from html where url='$url' and xpath='//tr[@class=\"tr-odd\"]'";
yql = yql.replace("$url",url);
var queryoutput = y.query(yql).results;
var i = 0;
var nrofitemstodelete = 0;
nrofitemstodelete = queryoutput..div.(@["class"] == 'opomba-layer').length(); // tooltip-footnotes
for (i=0;i<nrofitemstodelete;i++) {
delete queryoutput..div.(@["class"] == 'opomba-layer')[0];
}
nrofitemstodelete = queryoutput..span.(@["class"] == 'v').length(); // passage numbers
for (i=0;i<nrofitemstodelete;i++) {
delete queryoutput..span.(@["class"] == 'v')[0];
}
nrofitemstodelete = queryoutput..span.(@["class"] == 'c').length(); // chapter numbers
for (i=0;i<nrofitemstodelete;i++) {
delete queryoutput..span.(@["class"] == 'c')[0];
function listEditions(node) {
var value = "";
for each (var edition in node.children()) {
value += edition.input.(@name == 'true').toString();
if (edition.input.(@name != 'true').length() > 0) {
value += " (";
for each (var input in edition.input.(@name != 'true')) {
value += input.toString();
value += ",";
}
value = value.replace(/,$/,'');
value += ")";
}
nrofitemstodelete = queryoutput..div.(@["class"] == 's1').length(); // subtitles
for (i=0;i<nrofitemstodelete;i++) {
delete queryoutput..div.(@["class"] == 's1')[0];
}
nrofitemstodelete = queryoutput..div.(@["class"] == 's').length(); // subtitles
for (i=0;i<nrofitemstodelete;i++) {
delete queryoutput..div.(@["class"] == 's')[0];
}
nrofitemstodelete = queryoutput..div.(@["class"] == 'mt').length(); // chapter titles
for (i=0;i<nrofitemstodelete;i++) {
delete queryoutput..div.(@["class"] == 'mt')[0];
}
nrofitemstodelete = queryoutput..script.length(); // google ads
for (i=0;i<nrofitemstodelete;i++) {
delete queryoutput..script[0];
}
return <passage>{stringValue(queryoutput)}</passage>;
value += " - ";
value += edition.language.toString();
value += ", ";
}
value = value.replace(/, $/,'');
return value;
}
]]></execute>
</select>
</bindings>
Expand Down
Loading

0 comments on commit 6678949

Please sign in to comment.