Jump to content
McKay Development

Recommended Posts

Posted

Is there a way to set a variable of the price by using this package?

 

https://github.com/tarikkiziltan/getPrice

 

I saw there's

var Price = require("./getprice.js")
//var price = new Price(tag,craft,item,callBack) // What should i put in the callback if i want to use the price? Thanks


Price.getPrice("Vintage","Craftable","Gunslinger",function(price,priceType) {
	console.log("It's " + price + " " + priceType);
}) 
Posted

You can put a function that does something with the callback

Price.getPrice(tag, craft, itemName, (price, priceType) => {
    console.log("Price: " + price);
    console.log("Price Type: " + priceType)
});
  • tag : A string that includes your tag like "Vintage","Unique" and "Vintage"

  • craft: A string that includes your craft type like "Craftable" or "Non-Craftable"

  • itemName: A string that includes your items full name on BP.TF like "Taunt: Kazotsky Kick"

  • price: Price of item.

  • priceType: Type of price. Returns "key" or "ref"

 

I would like to recommend the OPSkins API for your pricing as you need less calls and you are not depending on another service to be online as you can save all the prices in a database or file. If you want i can provide an example code for this too

Posted

This is the code i use at the moment

"use strict";

const OPSkinsAPI = require('@opskins/api');
const opskins = new OPSkinsAPI(Your OPSkins API);
const mysql = require('mysql');

var con = mysql.createConnection({ // Your MySQL connection details
	host: '',
	user: '',
	password: '',
	database: ''
});

con.connect( (err) => {
	if (err) {
		throw err;
	} else {
		console.log('MySQL connected');
	}
});

setInterval( () => {

	if (new Date().getHours() === 22) {

		opskins.getPriceList(730, ( (err, prices) => {
			if (err) {
				console.log(err);
			} else {
				var names = Object.getOwnPropertyNames(prices);

				for (var i = 0; i <= names.length; i++) {

					var n;

					setTimeout( (i) => {

						if (i < names.length) {
							var name = '"' + names[i] + '"';
							var named = names[i];
							var date = Object.getOwnPropertyNames(prices[named]);
							var price = prices[named][date[0]].price;

							var sql = "INSERT INTO pricing(name, price) VALUES(" + name + ", " + price + ") ON DUPLICATE KEY UPDATE price = " + price + ";";

							con.query(sql, (err) => {
								if (err) {
									throw err;
								} else {
									n = i + 1;
									console.log('Updating prices.. ' + n + '/' + names.length);

									if (n === names.length) {
										console.log('Prices updated');
									}
								}
							});
						}

					}, 10 * i, i);
				}
			}
		}));
	}
}, 3600000);

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...