acpixel commented on a Page, JSON for MIRC  -  Aug 25, 2015

yo so i need a bit of help. so i need to get the value of time and player under each category.

the command would be !wr sm64 120_star. then the script would go to http://www.speedrun.com/api_records.php?game=sm64
then it would parse and find the values for player and time under the category 120 star. but because the game constantly changes i need to be able to read the first value and basely skip over it. but i want the end response to be "the world record for Super Mario 64 is (time) by (player)" but speedrun.com allows for abbreviations such as sm64, but i want the response to have the whole name. and the json does contain the whole name. so in the end i need to get the first value then parse to the time and player and output all 3.

here is my code so far.

on *:TEXT:!wr *:#: { 
  if (!%comwr) {
    set -u1 %comwr 1
    JSONOpen -u wr http://www.speedrun.com/api_records.php?game= $+ $replace($2 , _, $chr(32))
    msg $chan http://www.speedrun.com/api_records.php?game= $+ $replace($2 , _, $chr(32))
    msg $chan test $json(wr, (help needed), $replace($3 , _, $chr(32)))
    JSONClose wr
    else {
      msg $chan Sorry $nick $+ , no one is playing $2-
      JSONClose stream
    }
  }
  else {
    msg $chan Sorry $nick this command is on cooldown.
  }
}
SReject  -  Aug 25, 2015

Mkay, that API is not following generally accepted 'best' JSON practices: its using non-static data for item keys; due to this, my JSON parser may not correctly be able to handle this data.

With that said, you may be able to use $JSON().fuzzy to access the child members assuming that the child members to be accessed have non totally numeric keys:

JSONOpen -u wr http://www.speedrun.com/api_records.php?game= $+ $replace($2 , _, $chr(32))

;; get the first item* in the wr json's root object then get the user specifiec catagory
;; *: In json indexes start at 0 not 1
var %ref = $JSON(wr, 0, $replace($3 , _, $chr(32))).fuzzy

if ($JSONError) {
  ;; handle error
}
elseif (!%ref) {
  ;; catagory doesn't exist
}
else {
  ;; get player and time values
  var %player = $JSON(%ref, player)
  var %time = $json(%ref, time)

  ;; DO STUFF HERE WITH %player AND %time
}
acpixel  -  Aug 26, 2015

edit: i got it working <3 <3 <3 thank you so freaking much. i cant stress how helpful you are <3

acpixel  -  Aug 26, 2015

wait. i got it working!!!! much <3 <3 <3

SReject  -  Aug 26, 2015

No problem. :)

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.