Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require('express');
- var request = require('request');
- var fs = require('fs')
- var hiziprices = "Loading...";
- var getpriceshizi_timeout;
- app.listen(80, function() {
- console.log("=============================================================================================");
- console.log("======================================== App started ========================================");
- console.log("=============================================================================================");
- });
- setInterval(function() {
- console.log("[LOG] Clear queries counter...");
- for(var key in apiKeys) {
- console.log("[LOG] " + apiKeys[key].desc +". Queries: " +apiKeys[key].thisMin);
- apiKeys[key].thisMin = 0;
- }
- console.log("[LOG] All apikeys cleared.");
- }, 60000);
- app.get("/hiziprices/:apiKey", function(req, res) {
- var error = true;
- for(var key in apiKeys) {
- if(apiKeys[key].apiKey == req.params.apiKey) {
- var apiKey = apiKeys[key];
- console.log("[LOG] "+apiKey.desc + " IP: " + req.ip +". H1Z1 prices");
- if(apiKey.thisMin > apiKey.limit) {
- return res.json({
- error: "Try to load inventory in 1 minute. Your limit: " + apiKey.limit + ". You used " + apiKey.limit + ".",
- errorCode: 1
- });
- }
- apiKey.thisMin++;
- if(prices == "Loading...")
- res.send({
- 'success' : false,
- 'prices': hiziprices
- });
- else
- res.send({
- 'success' : true,
- 'prices': hiziprices
- });
- error = false;
- } else {
- error = true;
- }
- }
- if(error) {
- return res.json({
- error: "Your apiKey is bad. Please try another.",
- errorCode: 3
- });
- }
- });
- function getpriceshizi(){
- clearTimeout(getpriceshizi_timeout);
- request('https://opskins.com/pricelist/433850.json', function (error, response) {
- if(response.statusCode != 200 || response.success == 0) {
- console.log("[ERROR] Cant load items price H1Z1. Wait 60 seconds for upload new prices");
- hiziprices = "Loading...";
- getpricescsgo_timeout = setTimeout(function(){
- getpriceshizi();
- },60000);
- if(fs.existsSync(__dirname + '/hiziprices.txt')){
- var buffprices = JSON.parse(fs.readFileSync(__dirname + '/hiziprices.txt'));
- hiziprices = {};
- for(var key in buffprices){
- hiziprices[key] = buffprices.items[key].safe_net_price;
- }
- console.log("[LOG] H1Z1 old prices loaded from file")
- }
- } else {
- var buffprices = JSON.parse(response.body);
- fs.writeFileSync('hiziprices.txt', response.body);
- hiziprices = {};
- var price_date = false;
- for(var key in buffprices){
- if(!price_date){
- for(var keys in buffprices[key]){
- price_date = keys;
- }
- }
- if(buffprices[key][price_date] == undefined){
- console.log("[LOG] Price undefined: "+key);
- for(var dates in buffprices[key]){
- hiziprices[key] = (buffprices[key][dates].price / 100).toFixed(2);
- hiziprices[key] = hiziprices[key].toString();
- }
- continue;
- }
- hiziprices[key] = (buffprices[key][price_date].price / 100).toFixed(2);
- hiziprices[key] = hiziprices[key].toString();
- }
- console.log("[LOG] H1Z1 prices loaded!!!")
- }
- });
- }
- getpriceshizi();
- setInterval(getpriceshizi,21600000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement