Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. function loadSystemPrices(priceIDs,systemID,cachebuster){
  2. if (typeof systemID == 'undefined'){
  3. systemID=30000142;
  4. }
  5. if (typeof priceIDs == 'undefined'){
  6. throw 'need typeids';
  7. }
  8. if (typeof cachebuster == 'undefined'){
  9. cachebuster=1;
  10. }
  11. var prices = new Array();
  12. var dirtyTypeIds = new Array();
  13. var cleanTypeIds = new Array();
  14. var url="http://api.eve-central.com/api/marketstat?cachebuster="+cachebuster+"&usesystem="+systemID+"&typeid=";
  15. priceIDs.forEach (function (row) {
  16. row.forEach ( function (cell) {
  17. if (typeof(cell) === 'number' ) {
  18. dirtyTypeIds.push(cell);
  19. }
  20. });
  21. });
  22. cleanTypeIds = dirtyTypeIds.filter(function(v,i,a) {
  23. return a.indexOf(v)===i;
  24. });
  25. var parameters = {method : "get", payload : ""};
  26.  
  27. var o,j,temparray,chunk = 100;
  28. for (o=0,j=cleanTypeIds.length; o < j; o+=chunk) {
  29. temparray = cleanTypeIds.slice(o,o+chunk);
  30. var xmlFeed = UrlFetchApp.fetch(url+temparray.join("&typeid="), parameters).getContentText();
  31. var xml = XmlService.parse(xmlFeed);
  32. if(xml) {
  33. var rows=xml.getRootElement().getChild("marketstat").getChildren("type");
  34. for(var i = 0; i < rows.length; i++) {
  35. var price=[parseInt(rows[i].getAttribute("id").getValue()),
  36. parseInt(rows[i].getChild("buy").getChild("volume").getValue()),
  37. parseFloat(rows[i].getChild("buy").getChild("avg").getValue()),
  38. parseFloat(rows[i].getChild("buy").getChild("max").getValue()),
  39. parseFloat(rows[i].getChild("buy").getChild("min").getValue()),
  40. parseFloat(rows[i].getChild("buy").getChild("stddev").getValue()),
  41. parseFloat(rows[i].getChild("buy").getChild("median").getValue()),
  42. parseFloat(rows[i].getChild("buy").getChild("percentile").getValue()),
  43. parseInt(rows[i].getChild("sell").getChild("volume").getValue()),
  44. parseFloat(rows[i].getChild("sell").getChild("avg").getValue()),
  45. parseFloat(rows[i].getChild("sell").getChild("max").getValue()),
  46. parseFloat(rows[i].getChild("sell").getChild("min").getValue()),
  47. parseFloat(rows[i].getChild("sell").getChild("stddev").getValue()),
  48. parseFloat(rows[i].getChild("sell").getChild("median").getValue()),
  49. parseFloat(rows[i].getChild("sell").getChild("percentile").getValue())];
  50. prices.push(price);
  51. }
  52. }
  53. }
  54. return prices;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement