Advertisement
Guest User

Untitled

a guest
Feb 15th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. function getItemName(itemID) {
  2. var myUrl = "https://api.guildwars2.com/v2/items/" + escape(itemID);
  3. var jsonData = UrlFetchApp.fetch(myUrl);
  4. var jsonString = jsonData.getContentText();
  5. return jsonObject;
  6. }
  7.  
  8. function getItemBuyValue(itemID, upd) {
  9. var myUrl = "https://api.guildwars2.com/v2/commerce/listings/" + escape(itemID);
  10. var jsonData = UrlFetchApp.fetch(myUrl);
  11. var jsonString = jsonData.getContentText();
  12. var jsonObject = JSON.parse(jsonString).result;
  13. var adjustedValue = (jsonObject.max_offer_unit_price / 100);
  14. Utilities.sleep(1000);
  15. return adjustedValue;
  16. }
  17.  
  18. function GetItemSellValue(itemID) {
  19. var myUrl = "https://api.guildwars2.com/v2/commerce/listings/" + escape(itemID);
  20. var jsonData = UrlFetchApp.fetch(myUrl);
  21. var jsonString = jsonData.getContentText();
  22. var jsonObject = JSON.parse(jsonString).result;
  23. var adjustedValue = (jsonObject.min_sale_unit_price / 100 );
  24. Utilities.sleep(1000);
  25. return adjustedValue;
  26. }
  27.  
  28. function SalePriceChangedLastHour(itemID) {
  29. var myUrl = "https://api.guildwars2.com/v2/commerce/listings/" + escape(itemID);
  30. var jsonData = UrlFetchApp.fetch(myUrl);
  31. var jsonString = jsonData.getContentText();
  32. var jsonObject = JSON.parse(jsonString).result;
  33. var adjustedValue = (jsonObject.sale_price_change_last_hour / 100);
  34. Utilities.sleep(1000);
  35. return adjustedValue;
  36. }
  37.  
  38. function OfferPriceChangedLastHour(itemID) {
  39. var myUrl = "https://api.guildwars2.com/v2/commerce/listings/" + escape(itemID);
  40. var jsonData = UrlFetchApp.fetch(myUrl);
  41. var jsonString = jsonData.getContentText();
  42. var jsonObject = JSON.parse(jsonString).result;
  43. var adjustedValue = (jsonObject.offer_price_change_last_hour / 100);
  44. Utilities.sleep(1000);
  45. return adjustedValue;
  46.  
  47. function formatAsGold(sellValue) {
  48. var n = sellValue;
  49. var s = "";
  50. if (sellValue < 0) {
  51. s = "-";
  52. n = Math.abs(n);
  53. }
  54. var gold = Math.floor(((n / 10000) % 100));
  55. var silver = Math.floor(((n / 100) % 100));
  56. var copper = Math.floor((n % 100)) + "c";
  57. if (gold == 0) {
  58. gold = "";
  59. } else {
  60. gold += "g ";
  61. }
  62. if (silver == 0) {
  63. silver = "";
  64. } else {
  65. silver += "s ";
  66. }
  67. return s + gold + silver + copper;
  68. }
  69.  
  70. function getItemLastPriceChange(itemID) {
  71. var lastUpdate = getItemProperty(itemID, 'price_last_changed');
  72. return lastUpdate.substr(0,19); // shave off " UTC" part
  73. }
  74. }
  75.  
  76. function calcSDStatus(supply, demand, threshold) {
  77. if (typeof threshold === "undefined") {
  78. threshold = 0.05;
  79. }
  80. //supply = 212;
  81. //demand = 541;
  82. var ratio = supply / demand;
  83. var lowerBound = (ratio - threshold);
  84. var upperBound = (ratio + threshold);
  85. var status;
  86. if (ratio == 1.0) {
  87. status = "Equilibrium";
  88. } else if (lowerBound < 1.0) {
  89. status = "In Demand";
  90. } else { // upperBound > 1.0
  91. status = "Saturated";
  92. }
  93. return status;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement