Created
June 2, 2013 10:48
-
-
Save davidchambers/5693284 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cheerio = require 'cheerio' | |
request = require 'request' | |
tutor = require 'tutor' | |
request 'http://www.wizards.com/magic/tcg/events.aspx?x=mtg/event/playerschamp/2012/cubepool', | |
(err, res, body) -> | |
throw err if err? | |
$ = cheerio.load body | |
names = $('a.nodec').map -> @text() | |
cards = {} | |
done = 0 | |
for name in names then do (name) -> | |
tutor.card name, (err, card) -> | |
throw err if err? | |
{name, versions} = card | |
{expansion, rarity} = versions[(+k for k of versions).sort()[0]] | |
((cards[expansion] ?= {})[rarity] ?= []).push(name) | |
print cards if ++done is names.length | |
print = (cards) -> | |
for expansion of cards | |
console.log """ | |
\n | |
#{expansion} | |
#{(new Array expansion.length + 1).join('-')} | |
""" | |
for rarity, names of cards[expansion] | |
console.log "\n#{rarity}s:" | |
console.log "- #{name}" for name in names |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment