Topic: Helpful script to download a deck

Copy&pasting with a browser catches a lot of "[You have 4 cards in this set, but only 3 in your Inventory and Wishlist.]"
and related garbage, so I wrote a script to export a deck from deckbox. Paste URL, get deckbox to stdout.

I hope it will be of some use to others. By the way some function to export deck in simple text-based format would be pretty neat.

#!/usr/bin/env ruby

require "rubygems"
require "hpricot"

def extract_card(tr)
  count = (tr/".card_count")
  return nil if count.empty?
  [count.text.to_i, (tr/".card_name a").text]
end

def extract(url)
  body = `curl -s "#{url}"`
  doc = Hpricot(body)
  main = doc/".main.deck/tr"
  side = doc/".sideboard.deck/tr"
  main = main.map{|tr| extract_card(tr)}.compact
  side = side.map{|tr| extract_card(tr)}.compact
  [main, side]
end

url = ARGV[0]

main, side = extract(url)

puts "Mainboard (#{main.map{|cnt,name| cnt}.inject(&:+)}):"
puts main.map{|cnt, name| "#{cnt}x #{name}"}

unless side.empty?
  puts "\nSideboard (#{side.map{|cnt,name| cnt}.inject(&:+)}):"
  puts side.map{|cnt, name| "#{cnt}x #{name}"}
end

Re: Helpful script to download a deck

You could also copy/paste from the page generated for printing the deck...

Re: Helpful script to download a deck

Oh, I totally missed that one.

Re: Helpful script to download a deck

Trickster wrote:

You could also copy/paste from the page generated for printing the deck...

There's not even a need for that, you can just save it as a .txt file.