Sunday, December 9, 2012

gw2spidy API in Google Docs on Steroids

  Guild Wars 2 is pretty much dead to me, but I find gw2spidy's API fascinating and fun to play with.  I'm not a professional programmer by trade but I find it interesting to play around with this kind of stuff.  Before I was pulling the data into Excel and manipulating it using the article linked below written by Marthisdil.


  Granted, I took it way farther than Marthisdil did in his article, but all the basics for doing it yourself are in there.  I read a similar simple little how-to by Valaadus where he was doing the same thing in Google docs with JSON and a little Javascript.


  This is particularly interesting to me because its web based and uses google doc's API which is by itself incredible.  So this is what I've created (sample).  Instead of using the CSV calls I used in my previous implimentation I'm using json calls.  Below is an example of a json call, clicking this will just throw up some junk on the screen.  Below that is what the call looks like in a little bit more understandable format.



  The example written up by Valaadus was parsing the results of a json request for min_sale_unit_price and formatting it a little bit with some javascript.  I wanted to see if I could return an entire row of values using only the item ID, and then do some more in depth calculations.  I modified the script as shown below.


  Lines 5-8 are where the data is fetched, and 10-14 are where I grab each of the individual items I want out of the string returned in the json call (first graphic).  Usually you can't modify the contents of cells arbitrarily in functions, but if you format it like I've done they "spill over" into cells to the right.  You can view my sheet below.


  Column B is the only column that calls the function =getItemInfo() and its fed column A for the itemID. Columns B, C, D, E, and F are populated with that function call because of the way the return statement is formatted.  Columns G-P are normal excel formulas.  I'm calculating projected earnings, total investment required, and the return on that investment (i.e., how fast your gold will grow by flipping this item).


  Gemstones and Jewels were always a pretty good market for me, as long as you didn't dive very deep.  Using the sheet you can simply refresh the page and sort by ROI, or the Earning column to see what to buy and sell.

  To keep things simple I left all units of measure in copper.  Really you only need to know that more profit is better anyway... so the units don't matter much.  It's all simple math anyway */ 100.  The big challenge with doing this in Google documents is that their API limits the amount of function calls you can make in a given time, so you've got to write the script to pull more data per query, and use some javascript to dump the data in the sheet with an array.  Really gw2spidy's API will have to mature a little so you can get better defined querying before this becomes useful.

Enjoy!