Advertisement
VeryGoodGirl

Untitled

May 23rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. var express = require('express');
  2. var request = require('request');
  3. var fs = require('fs')
  4. var hiziprices = "Loading...";
  5. var getpriceshizi_timeout;
  6.  
  7. app.listen(80, function() {
  8. console.log("=============================================================================================");
  9. console.log("======================================== App started ========================================");
  10. console.log("=============================================================================================");
  11. });
  12.  
  13. setInterval(function() {
  14. console.log("[LOG] Clear queries counter...");
  15. for(var key in apiKeys) {
  16. console.log("[LOG] " + apiKeys[key].desc +". Queries: " +apiKeys[key].thisMin);
  17. apiKeys[key].thisMin = 0;
  18. }
  19. console.log("[LOG] All apikeys cleared.");
  20. }, 60000);
  21.  
  22. app.get("/hiziprices/:apiKey", function(req, res) {
  23. var error = true;
  24. for(var key in apiKeys) {
  25. if(apiKeys[key].apiKey == req.params.apiKey) {
  26. var apiKey = apiKeys[key];
  27. console.log("[LOG] "+apiKey.desc + " IP: " + req.ip +". H1Z1 prices");
  28. if(apiKey.thisMin > apiKey.limit) {
  29. return res.json({
  30. error: "Try to load inventory in 1 minute. Your limit: " + apiKey.limit + ". You used " + apiKey.limit + ".",
  31. errorCode: 1
  32. });
  33. }
  34. apiKey.thisMin++;
  35. if(prices == "Loading...")
  36. res.send({
  37. 'success' : false,
  38. 'prices': hiziprices
  39. });
  40. else
  41. res.send({
  42. 'success' : true,
  43. 'prices': hiziprices
  44. });
  45. error = false;
  46. } else {
  47. error = true;
  48. }
  49. }
  50. if(error) {
  51. return res.json({
  52. error: "Your apiKey is bad. Please try another.",
  53. errorCode: 3
  54. });
  55. }
  56. });
  57.  
  58. function getpriceshizi(){
  59. clearTimeout(getpriceshizi_timeout);
  60. request('https://opskins.com/pricelist/433850.json', function (error, response) {
  61. if(response.statusCode != 200 || response.success == 0) {
  62. console.log("[ERROR] Cant load items price H1Z1. Wait 60 seconds for upload new prices");
  63. hiziprices = "Loading...";
  64. getpricescsgo_timeout = setTimeout(function(){
  65. getpriceshizi();
  66. },60000);
  67. if(fs.existsSync(__dirname + '/hiziprices.txt')){
  68. var buffprices = JSON.parse(fs.readFileSync(__dirname + '/hiziprices.txt'));
  69. hiziprices = {};
  70. for(var key in buffprices){
  71. hiziprices[key] = buffprices.items[key].safe_net_price;
  72. }
  73. console.log("[LOG] H1Z1 old prices loaded from file")
  74. }
  75. } else {
  76. var buffprices = JSON.parse(response.body);
  77. fs.writeFileSync('hiziprices.txt', response.body);
  78. hiziprices = {};
  79. var price_date = false;
  80. for(var key in buffprices){
  81. if(!price_date){
  82. for(var keys in buffprices[key]){
  83. price_date = keys;
  84. }
  85. }
  86. if(buffprices[key][price_date] == undefined){
  87. console.log("[LOG] Price undefined: "+key);
  88. for(var dates in buffprices[key]){
  89. hiziprices[key] = (buffprices[key][dates].price / 100).toFixed(2);
  90. hiziprices[key] = hiziprices[key].toString();
  91. }
  92. continue;
  93. }
  94. hiziprices[key] = (buffprices[key][price_date].price / 100).toFixed(2);
  95. hiziprices[key] = hiziprices[key].toString();
  96. }
  97. console.log("[LOG] H1Z1 prices loaded!!!")
  98. }
  99. });
  100. }
  101. getpriceshizi();
  102. setInterval(getpriceshizi,21600000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement