I have this code, the thing with it is, I need it to get some data from that website, the string in apiurl. This code needs to download these websites, with the certain appids found in the json. It needs to download the data on these websites and store them in a json file. For some reason this does not work.
I have this piece of code in a .js file:
var gamekeys = JSON.parse(fs.readFileSync('gamekeys.json'));
var jsonstring = JSON.stringify(gamekeys, null, 4);
UpdateGamePricelist();
function UpdateGamePricelist() {
for(var i = 0;i<gamekeys.keys.length;i++) {
appid = gamekeys.keys[i].appid;
var apiurl = "http://store.steampowered.com/api/appdetails?appids="+appid;
if (i < 95) {
request(apiurl, function(err, response, body) {
if (err) {
console.log("Error when updating game prices: " + err+"\n");
return;
}
var apiresponse = JSON.parse(body);
if (body == "") {
console.log("Could not find a pricelist m8");
return;
}
fs.writeFile("C:/Users/ahmad/Desktop/Bots/SteamKeyProfitter/gamespricelist/"+appid+".json", body, function(err) {
if(err) {
console.log("Error saving data to game pricelist: " + err);
return;
}
console.log("Game pricelist has been updated!");
});
});
}
}
}
And I have a json file, the json file called gamekeys.json
Here it is:
{
"keys": [
{
"appid": 10,
"price":0,
"listofkeys":[],
"game": "Counter-Strike"
},
{
"appid": 20,
"price":0,
"listofkeys":[],
"game": "Team Fortress Classic"
},
{
"appid": 30,
"price":0,
"listofkeys":[],
"game": "Day of Defeat"
},
{
"appid": 40,
"price":0,
"listofkeys":[],
"game": "Deathmatch Classic"
},
It ofcourse keeps going (2 million lines of that)
Why does the first code not create 95 json files?