JSON

My inability to debug JavaScript is boundless.

When my script accesses

https://museum.loathers.net/player/2115655?_data=routes/player.$id._index

(or similar) it no longer returns any data. I don't know of anything that has changed on my end.

I will accept the possibility that this feature is Beta, unsupported or unmaintained but I much prefer using it to the previous alternative which was to pull a DCDB page for each item and then scrap each page for the characters I was interested in. Add in a whole lot of caching and time stamping since 10,000 items should not be queried in a session if I want a script that won't be banned at ColdFront.

In the spirt of self help I caught an exception that might have told me why there was no data, but

Code:
catch (e) {
   console.error(e);
}

tells me it doesn't know about console. I could not relate the suggested fixes for operating in a browser environment to running JavaScript from KoLMafia. I also could not figure out an equivalent of a print command which I hoped would just display a string where all my other output is being sent. I am probably missing something obvious or overthinking something but that could be the story of my life.

Thank you.
 
It looks like the URL has moved to https://museum.loathers.net/api/player/2115655?routes/player.$id._index (as @Ryo_Sangnoir pointed out in May)

Code:
let kolmafia = require("kolmafia")

let results = {};

for (let playerId of [1, 354981]) {
  let url = `https://museum.loathers.net/api/player/${playerId}?routes=player.%24id._index`;
  let obj = JSON.parse(kolmafia.visitUrl(url, false, true));
  let collection = obj.collections.map(x => { return {id: x.itemid, quantity: x.quantity, rank: x.rank}; });
  results[playerId] = collection;
}

kolmafia.print(JSON.stringify(results))
seems to work for me.
 
Last edited:
Not to be rude but I have to say this: it's not a beta feature, it is a totally unsupported implementation detail that I don't have any remote interest in maintaining.
 
It looks like the URL has moved to https://museum.loathers.net/api/player/2115655?routes/player.$id._index (as @Ryo_Sangnoir pointed out in May)

Code:
let kolmafia = require("kolmafia")

let results = {};

for (let playerId of [1, 354981]) {
  let url = `https://museum.loathers.net/api/player/${playerId}?routes=player.%24id._index`;
  let obj = JSON.parse(kolmafia.visitUrl(url, false, true));
  let collection = obj.collections.map(x => { return {id: x.itemid, quantity: x.quantity, rank: x.rank}; });
  results[playerId] = collection;
}

kolmafia.print(JSON.stringify(results))
seems to work for me.

I thought I had done @Ryo_Sangnoir's fix because I edited and things worked. I just "fixed" it and got a 403. I will revisit in a couple of hours because I'm almost late for a meeting.

I see you answered my print question so thank you.
 
Not to be rude but I have to say this: it's not a beta feature, it is a totally unsupported implementation detail that I don't have any remote interest in maintaining.

I understand. I like the feature very much and would like it to be maintained. I am walking a fine line between annoying you so much that you give in and maintain it or annoying you so much that you rip it out completely. The former makes the world a better place because it means I don't have to web scrape to get the data I want.

But you are not being rude and I am sorry if my choice of language implied I felt entitled.
 
The JS portion is working as I hope and understand. I think I now have some tools and understanding so that if things stop working I can get farther along than I did this time. My big takeaway is that the name of JSON "fields" has to match the code and the data and I was not using that to debug. Thank you.
 
Back
Top