2017-06-20 136 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