fuzzysteve / eve-googledocs-script

Somewhere to stick functions for googledocs
MIT License
106 stars 32 forks source link

Feature Request: Function that returns the number of sell orders for each item in specified station. #9

Closed PLyczkowski closed 8 years ago

PLyczkowski commented 8 years ago

Here is my feeble and uninformed attempt (throws an error - "server was not able to produce a timely response"):

function sellOrdersAmount(priceIDs,systemID,cachebuster){

  if (typeof systemID == 'undefined'){
    systemID=30000142;
  }
  if (typeof priceIDs == 'undefined'){
    throw 'need typeids';
  }
  if (typeof cachebuster == 'undefined'){
    cachebuster=1;
  }

  var order_amounts = new Array();
  var dirtyTypeIds = new Array();
  var cleanTypeIds = new Array();
  var url="http://api.eve-central.com/api/quicklook?cachebuster="+cachebuster+"&usesystem="+systemID+"&typeid=";
  priceIDs.forEach (function (row) {
    row.forEach ( function (cell) {
      if (typeof(cell) === 'number' ) {
        dirtyTypeIds.push(cell);
      }
    });
  });
  cleanTypeIds = dirtyTypeIds.filter(function(v,i,a) {
    return a.indexOf(v)===i;
  });

  var parameters = {method : "get", payload : ""};

  for (var j = 0; j < cleanTypeIds.length; j++) {
    var xmlFeed = UrlFetchApp.fetch(url, parameters).getContentText();
    var xml = XmlService.parse(xmlFeed);
    if(xml) {

      for(var i = 0; i < item_amount; i++) {

        var order_amount = xml.getRootElement().getChild("quicklook").getChildren("sell_orders").length;

        order_amounts.push(order_amount);
      }
    }
  }
  return order_amounts;
}
fuzzysteve commented 8 years ago

This is really getting into potentially large data, which isn't particularly suited to spreadsheet functions. (especially not google, with process limits)

I'd highly recommend looking into something which downloads the market into a local database instead, and queries there.