2017-06-20 125 views
0

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

雅虎是否更新了他们的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

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

例如用于提取html代替:

select * from html 

您可以使用:

select * from htmlstring 

Read here

+0

有这种怪事释放或通知说,支持是下降了吗? –

+0

@PT_C是的,他们放弃了对'html'的支持,但是'htmlstring'仍然有效,因为它支持yahoo的开发者社区。 – Rubioli

+0

尝试在浏览器中运行您的查询,结果会说,Yahoo已停止支持'html' – Rubioli