创建YQL Opentable以将RSS数据与Placemaker地图信息结合起来

问题描述:

我试图从RSS提要中检索数据(使用此部分),然后使用描述,标题和标题用于获取地理信息(纬度,经度,woeId)使用YQL Placemaker打开数据表。创建YQL Opentable以将RSS数据与Placemaker地图信息结合起来

这是所有需要输出为JSON。

在YQL控制台中测试它的永久链接是here

任何想法什么是错误的我的XML代码或我应该尝试什么?

<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> 
+0

嗨伊姆兰,主要问题是你的''块有点混乱。你想要做的事很可能,你是否自己做过这些事情? – salathe 2011-06-07 22:17:08

一个整理了(并且它带回RSS + Placemaker结果意义上的 “工作”),您的表的版本是这样的:

<?xml version="1.0" encoding="UTF-8" ?> 
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd"> 
    <meta> 
    <author>Peter Cowburn</author> 
    <documentationURL>http://*.com/questions/6168564/creating-a-yql-opentable-to-combine-rss-data-with-placemaker-map-info</documentationURL> 
    <sampleQuery>select * from {table} where section='topstories'</sampleQuery> 
    <description>Searches Yahoo! News RSS and injects Placemaker Places</description> 
    </meta> 
    <bindings> 
    <select itemPath="stories.story" produces="XML"> 
     <urls> 
     <url> 
      http://rss.news.yahoo.com/rss/{section} 
     </url> 
     </urls> 
     <inputs> 
     <key id="section" type="xs:string" paramType="path" required="true" /> 
     </inputs> 
     <execute><![CDATA[ 

// Fetch top 30 feed items with jpg images 
var feed = y.query(
    'select * from rss where [email protected] and description matches ".*jpg.*" limit 30', 
    {url: request.url} 
).results; 

// Build geo queries 
var placeQuery = 'select * from geo.placemaker where [email protected] and documentType="text/plain"'; 
var placeQueries = []; 
var title, description, caption, summary, content; 
for each (result in feed.item) { 
    title  = result.title.text().toString(); 
    description = y.tidy(result.description.toString()).body.p; 
    caption  = [email protected](); 
    summary  = description..*.text().toString(); 
    content  = caption + " " + title + " " + summary; 
    placeQueries.push({ 
    query: y.query(placeQuery, {text: content}), 
    item: result, 
    results: null 
    }); 
} 

// Execute all queries 
var where = new Namespace('http://wherein.yahooapis.com/v1/schema'); 
var matches, match, places = []; 
for (var q in placeQueries) { 
    matches = placeQueries[q].query.results.matches.match; 
    placeQueries[q].results = matches..where::place; 
} 

// Build response object 
var stories = <stories/>; 
for each (q in placeQueries) { 
    stories.node += <story> 
    {q.item} 
    {q.results} 
    </story>; 
} 

response.object = stories; 

     ]]></execute> 
    </select> 
    </bindings> 
</table> 

你可以用它通过指向在线表(它可能不会永远在附近!)在如下查询中:

use 'https://raw.github.com/salathe/yql-tables/so-6168564/yahoo/newswithplaces.xml' 
as rssplaces; 
select * from rssplaces where section='topstories'; 

Try this in the YQL console

表使用了一些在<execute>块像E4X,查询参数和并行查询中提供的功能,所有使生活更方便,但可能会在第一眼略有国外。

P.S.以上是按原样提供的,我不打算在这方面向后面回答“支持”问题。它的主要目的是为了让你感动,介绍一种可能适合你的方法。