Skip to content

Instantly share code, notes, and snippets.

@davidchambers
Created June 2, 2013 10:48
Show Gist options
  • Save davidchambers/5693284 to your computer and use it in GitHub Desktop.
Save davidchambers/5693284 to your computer and use it in GitHub Desktop.
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