0

Creating a YQL Opentable to combine RSS data with Placemaker Map info

I am trying to retrieve data from a RSS feed (succeeding with this part) and then using the description, title and caption to be used to get Geo information (latitude, longitude, woeId) using YQL Placemaker open datatable.

This is all then needed to be output as JSON.

The permalink to test it in the YQL console is http://y.ahoo.it/yP9j0EYK

Any ideas whats wrong with my xml code or what should I try instead?


CODEBOX
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">

<meta>
<author>Yahoo! Inc.</author>
<documentationURL>http://i-magine.mobi/</documentationURL>
<sampleQuery>select * from {table} where section="topstories" and description matches ".*jpg.*"</sampleQuery>
<description>Searches Yahoo.news RSS</description>
</meta>


<bindings>
<select itemPath="" produces="XML">
<urls>
<url>http://rss.news.yahoo.com/rss/topstories/{section}
</url>
</urls>
<inputs>
<key id='section' type="xs:string" paramType="path" required="true" />
</inputs>


<execute><![CDATA[
default xml namespace = "http://where.yahooapis.com/v1/schema.rng";

// http://www.json.org/json2.js
y.include('http://www.i-magine.mobi/json2.js');

rssStorySection = [];

rssStoryNumber = [];
rssStoryTitle = [];
rssStorySummary = [];
rssImageCaption = [];
rssStoryUrl = [];
rssImageUrl = [];

rssGeoText = [];

// var content = 'They followed him to deepest Africa after Brussels and Tokyo and found him there in Timbuktu';

var rssQuery = 'select * from rss where url = ' + "'" + 'http://rss.news.yahoo.com/rss/' + section + "'" + ' and description matches ".*jpg.*" limit 30';


res1 = y.query(rssQuery);
data1 = res1.results;


// var geoQuery = 'SELECT * FROM geo.placemaker WHERE documentContent =' + '"' + content + '"' + 'AND documentType=' + '"' + 'text/plain' + '"';


// res2 = y.query(geoQuery);
// data2 = res2.results;



for (var c=0;c<data1.item.length;c++)
{
var story = data1.item[c];

var storyTitleText0 = story.title + "";

var storyUrl = story.link + "";

var description = story.description;

var storyTitleText = storyTitleText0.replace(/\n/ig, "") + "";

var imageUrl = description.match(/http:\/\/d.*?jpg/i) + "";

var imageCaptionText0 = description.match(/alt="([^ ]).*border/) + "";
var imageCaptionText1 = imageCaptionText0.replace(/alt="/ig, "") + "";
var imageCaptionText = imageCaptionText1.replace(/" border.*/ig, "") + "";

var storySummaryText = description.replace(/<[^>]*>([\s]?)*<[^>]*>/g, "") + "";

var storySection0 = description.match(/http[^ ].*\*/i) + "";
var storySection1 = storySection0.replace(/\/\*/ig, "") + "";
var storySection = storySection1.replace(/http:\/\/us.rd.yahoo.com\/dailynews\/rss\//ig, "") + "";

var geoString = (imageCaptionText + " " + storyTitleText + " " + storySummaryText);

rssStorySection.push(storySection);
rssStoryTitle.push(storyTitleText);
rssStorySummary.push(storySummaryText);
rssImageCaption.push(imageCaptionText);
rssStoryUrl.push(storyUrl);
rssImageUrl.push(imageUrl);
rssGeoText.push(geoString);
rssStoryNumber.push(c);

var content = geoString;

var geoQuery = 'SELECT * FROM geo.placemaker WHERE documentContent =' + '"' + content + '"' + 'AND documentType=' + '"' + 'text/plain' + '"';


var res2 = y.query(geoQuery);
var data2 = res2.results;

}


var d = data1;
var e = data2;

response.object = <stories>
<c>{section}</c>
<d>{d}</d>
<e>{e}</e>
</stories>;



]]></execute>



</select>
</bindings>
</table>

by
0 Replies

Recent Posts

in YQL