YQL查询突然失败

时间:2017-06-20 17:49:05

标签: csv yahoo yql

我们正在利用YQL从CSV中检索外部数据。最近,查询已全面返回null,我们无法弄清楚原因。

雅虎是否更新了他们的API?

查询

http://query.yahooapis.com/v1/public/yql?q=select * from csv where url IN ('http://www.iso-ne.com/transform/csv/fiveminlmp/current?type=prelim') AND col1 IN ('4014')

商品

http://query.yahooapis.com/v1/public/yql?q=select * from yql.storage where name='store://ueZTPNC1PAVBw7lBz8FWNu'

代码

<execute><![CDATA[ 
   y.log("Version 4.1");
    function getTimeQueryParam(){
      var d = new Date();
      var year = d.getFullYear();
      var month = d.getMonth();
      var day = d.getDate();
      var hr = d.getHours();
      var min = d.getMinutes();
      var sec = d.getSeconds();
      return '' + year + month + day + hr + min + sec;
    }
        //selects the current interval of LMP prices from ISO-NE
   var newData = null; 
   newData = y.query("select * from csv where url IN ('http://www.iso-ne.com/transform/csv/fiveminlmp/current?type=prelim') AND col1 IN ('4014')");
   newData = newData.results.row;
   if(newData == null || newData == ''){
        y.log("No New Data. Retry");
        newData = y.query("select * from csv where url IN ('http://www.iso-ne.com/transform/csv/fiveminlmp/current?type=prelim') AND col1 IN ('4014')");
        newData = newData.results.row;
   }    
   y.log("Current time interval: " + newData.col2);
        //selects the data stored in our YQL storage table for this tieline     

    var oldData = null; 
   oldData = y.query("select * from yql.storage where name='store://ueZTPNC1PAVBw7lBz8FWNu'");

   var results = oldData.results.result;
    y.log("results = oldData.results.result: " + results);
    var resultsJSON = y.xmlToJson(results);
    y.log("data JSON: " + y.jsToString(resultsJSON));

    var data = resultsJSON.result.value;
    var count = data.length;


    //checks to make sure the current time interval has not been added to store
   if(newData.col2 != data[data.length-1].col2){
        //24 = MAX_NUMBER of intervals we want to keep
        //delete oldest entries
        y.log("Oldest time interval before delete: " + data[0].col2);        
        if(count > 24){
            var deleteNum = count - 24;
            for(d = 0; d < deleteNum; d++) data.shift();
        }
        y.log("Oldest time interval after delete: " +data[0].col2);
        //adds current interval to store
        data[data.length] = newData;     
   }
        //creates JSONString from data Array, only text format can be stored in YQL storage 
   var txt = '[';
   for(i = 0; i < data.length; i++){
    txt = txt + '{"col0":"' + data[i].col0 + '", ';
    txt = txt + '"col1":"' + data[i].col1 + '", ';
    txt = txt + '"col2":"' + data[i].col2 + '", ';
    txt = txt + '"col3":"' + data[i].col3 + '", ';
    txt = txt + '"col4":"' + data[i].col4 + '", ';
    txt = txt + '"col5":"' + data[i].col5 + '", ';
    txt = txt + '"col6":"' + data[i].col6 + '"} ';
    if(i+1 < data.length)txt = txt + ', ';
   }    
   txt = txt + ']';
        //updates the YQL Storage Table with new data set       
   var status = y.query("update yql.storage set value='" + txt + "'where name='" + update + "'");
   y.log(status);
        //pulls newly updated data for queries on this YQL table
   var updatedData = y.query("select * from yql.storage where name='store://ueZTPNC1PAVBw7lBz8FWNu'");
   response.object = updatedData.results.result;   
      ]]></execute>

1 个答案:

答案 0 :(得分:1)

雅虎刚刚停止了对YQL的支持。至少他们html extract api。您可以做的一件事是从社区开放数据表的一部分运行YQL函数。

例如,用于提取html而不是:

select * from html

您可以使用:

select * from htmlstring

Read here