davidchambers / tutor

JavaScript interface for the Gatherer card database
https://gatherer.wizards.com/
Do What The F*ck You Want To Public License
149 stars 18 forks source link

tutor can't handle wizards redirecting requests for Arabian Night, Fire&Lightning, and Graveborn #69

Closed robdennis closed 10 years ago

robdennis commented 11 years ago
bin/tutor set "Premium Deck Series: Fire and Lightning"
Error: unexpected status code
bin/tutor set "Premium Deck Series: Graveborn"
Error: unexpected status code
bin/tutor set "Arabian Nights"
Error: unexpected status code

using the script from the wiki: https://github.com/davidchambers/tutor/wiki/Interact-with-the-CLI-from-other-applications

I programmatically tested every other set (as of today), and they're all fine

robdennis commented 11 years ago

adding a console.log of the result to gatherer.coffee if the statusCode isn't 200: apparently Arabian Nights is redirecting to the Arabian Nights mountain? here's me logging the urls requested:

$ bin/tutor set "Arabian Nights"
http://gatherer.wizards.com/Pages/Search/Default.aspx?action=advanced&output=spoiler&set=%5B%22Arabian%20Nights%22%5D&special=true
http://gatherer.wizards.com/Pages/Search/Default.aspx?set=%5B%22Arabian%20Nights%22%5D&type=%2B%5B%22Basic%22%5D%2B%5B%22Land%22%5D

here's the relavent result object with the non-200 status code

  body: '<html><head><title>Object moved</title></head><body>\r\n<h2>Object moved to <a href="%2fPages%2fCard%2fDetails.aspx%3fmultiverseid%3d983">here</a>.</h2>\r\n</body></html>\r\n' }
Error: unexpected status code

compare this to Shards of Alara, which totally works:

$ bin/tutor set "Shards of Alara"
http://gatherer.wizards.com/Pages/Search/Default.aspx?action=advanced&output=spoiler&set=%5B%22Shards%20of%20Alara%22%5D&special=true
http://gatherer.wizards.com/Pages/Search/Default.aspx?set=%5B%22Shards%20of%20Alara%22%5D&type=%2B%5B%22Basic%22%5D%2B%5B%22Land%22%5D
robdennis commented 11 years ago

my theory is that these three sets all share the quality of having exactly one type of basic land (AN and PDS F&L have mountain, PDS: GB have swamp) and wizards is "helpfully" redirecting you to the individual card page

robdennis commented 11 years ago

checking out the issue-52 branch seems to work on my local OS X install:

jane-air:tutor rad3$ bin/tutor set "Arabian Nights" | head -n 1
Abu Ja'far {W} 0/1 When Abu Ja'far dies, destroy all creatures blocking or blocked by it. They can't be regenerated.

the reason that this wasn't merged in before was some nebulous hanging issue I was seeing on ubuntu. Since "something" needs to change anyway, and travis is running on ubuntu, perhaps it's worth merging it in and seeing if travis complains

robdennis commented 10 years ago

so, on the latest master, I don't see this issue anymore. I theorized it's because of #74, but unsure. I'll be closing this, but if my theory makes sense for @davidchambers I'd feel better

davidchambers commented 10 years ago

It took me quite some time to get to the bottom of this one…

In #74, I accidentally removed followRedirect: no. Prior to this change, calls to tutor.set failed — Error: unexpected status code — for the sets mentioned in this issue. After the change, such calls appeared to work correctly.

Since /Pages/Search/Default.aspx?set=["Arabian Nights"]&type=+["Basic"]+["Land"], for example, redirects to /Pages/Card/Details.aspx?multiverseid=983, the following code now fails silently:

load(body2)('.cardItem').each ->
  ids = basics[@find('.cardTitle').text().trim()] = []
  @find('.setVersions').find('a').filter ->
    if @children("img[alt^='#{name}']").length
      ids.push +url.parse(@attr('href'), yes).query.multiverseid

Fire and Lightning contains just one of the basic lands, Mountain, but four distinct basic land cards. The above code, added in #66, fails silently for this set, since Mountain has no elements with the cardItem class name. As a result, three of the four Mountain cards in Fire and Lightning are omitted. This is a (minor) bug.