Created
May 17, 2014 22:18
-
-
Save mrmemes-eth/6826d3ae4c05338a495b to your computer and use it in GitHub Desktop.
Parse the CSV output from MTGO v3 client and rewrite it in a format that's compatible with the Decked Builder collection converter here: http://www.mtgo-stats.com/convert_coll/em
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
#! /usr/bin/env ruby | |
# This ruby script parses the CSV output from MTGO v3 client and rewrites it in | |
# a format that's compatible with the Decked Builder collection converter here: | |
# | |
# http://www.mtgo-stats.com/convert_coll/em | |
# | |
# If you're not sure how to export a CSV from the v3 client, see the | |
# instructions here: | |
# | |
# http://www.mtgotraders.com/buylist/ | |
# | |
# Some Important Notes: | |
# | |
# * The v3 client currently (May 2014) outputs set abbreviations that are not | |
# correct: e.g. Invasion is shown as IN when it should be INV. I manually | |
# edited my output CSV from the client to resolve this issue. If you do not | |
# wish to do so, you may, for example, change the SETS["INV"] entry to | |
# SETS["IN"]. | |
# | |
# affected sets from my collection: INV (IN), PLS (PS), APC (AP), USG (UZ), | |
# ULG (UL), MMQ (MM), NEM (NE), MIR (MI), 7ED (7E), APC (AP), STH (ST) | |
# | |
# * Certain other sets are not available in Decked Builder (Vanguard, Promos, | |
# Theme Deck Set, etc). I've provided abbreviation conversions for the sake | |
# of completeness, but they will not be included in conversions using the | |
# tool from mtgo-stats.com and will show as warnings in the email they send | |
# you with the coll2 file attached. | |
# | |
# * The composite character "Æ" is not supported in Decked Builder. I did a | |
# find and replace to swap it to "AE". | |
# | |
# * I did not unify foil counts and non-foil counts in the same column, since I | |
# didn't have much overlap in cards that were in the same set and I had both | |
# foil and non-foil versions. This is a side-effect of the fact that the v3 | |
# client CSV outputs separate rows for "Premium" (foil) cards... I'm unsure | |
# what the effect on the mtgo-traders.com converter is as a result of this. | |
# | |
# * This script is released under the terms of the WTFPL | |
# (http://www.wtfpl.net/) feel free to do whatever you want with it. | |
require 'csv' | |
SETS = { "10E" => "Tenth Edition", | |
"2ED" => "Unlimited Edition", | |
"3ED" => "Revised Edition", | |
"4ED" => "Fourth Edition", | |
"5DN" => "Fifth Dawn", | |
"5ED" => "Fifth Edition", | |
"6ED" => "Classic Sixth Edition", | |
"7ED" => "Seventh Edition", | |
"8ED" => "Eighth Edition", | |
"9ED" => "Ninth Edition", | |
"ALA" => "Shards of Alara", | |
"ALL" => "Alliances", | |
"APC" => "Apocalypse", | |
"ARB" => "Alara Reborn", | |
"ARC" => "Archenemy", | |
"ARN" => "Arabian Nights", | |
"ATQ" => "Antiquities", | |
"DDH" => "Duel Decks: Ajani vs. Nicol Bolas", | |
"AVR" => "Avacyn Restored", | |
"BNG" => "Born of the Gods", | |
"BOK" => "Betrayers of Kamigawa", | |
"BRB" => "Battle Royale", | |
"BTD" => "Beatdown", | |
"C13" => "Commander 2013 Edition", | |
"CHK" => "Champions of Kamigawa", | |
"CHR" => "Chronicles", | |
"CMD" => "Commander", | |
"CON" => "Conflux", | |
"CSP" => "Coldsnap", | |
"DDG" => "Duel Decks: Knights vs. Dragons", | |
"DDJ" => "Duel Decks: Izzet vs Golgari", | |
"DDK" => "Duel Decks: Sorin vs. Tibalt", | |
"DDM" => "Duel Decks: Jace vs. Vraska", | |
"DDN" => "Duel Decks: Speed vs. Cunning", | |
"DGM" => "Dragon's Maze", | |
"DIS" => "Dissension", | |
"DKA" => "Dark Ascension", | |
"DKM" => "Deckmasters", | |
"DRB" => "From the Vault: Dragons", | |
"DRK" => "The Dark", | |
"DST" => "Darksteel", | |
"DDC" => "Duel Decks: Divine vs. Demonic", | |
"EVE" => "Eventide", | |
"DDF" => "Duel Decks: Elspeth vs. Tezzeret", | |
"EXO" => "Exodus", | |
"FEM" => "Fallen Empires", | |
"FTV" => "From the Vault: Twenty", | |
"FUT" => "Future Sight", | |
"FVR" => "From the Vault: Realms", | |
"GPT" => "Guildpact", | |
"GTC" => "Gatecrash", | |
"DDD" => "Duel Decks: Garruk vs. Liliana", | |
"H09" => "Slivers", | |
"H10" => "Fire & Lightning", | |
"HML" => "Homelands", | |
"DDL" => "Duel Decks: Heroes vs. Monsters", | |
"ICE" => "Ice Age", | |
"INV" => "Invasion", | |
"ISD" => "Innistrad", | |
"JOU" => "Journey into Nyx", | |
"JUD" => "Judgment", | |
"DD2" => "Duel Decks: Jace vs. Chandra", | |
"LEA" => "Limited Edition Alpha", | |
"LEB" => "Limited Edition Beta", | |
"LEG" => "Legends", | |
"LGN" => "Legions", | |
"LRW" => "Lorwyn", | |
"M10" => "Magic 2010", | |
"M11" => "Magic 2011", | |
"M12" => "Magic 2012", | |
"M13" => "Magic 2013", | |
"M14" => "Magic 2014 Core set", | |
"MBS" => "Mirrodin Besieged", | |
"MED" => "Masters Edition", | |
"ME2" => "Masters Edition II", | |
"ME3" => "Masters Edition III", | |
"ME4" => "Masters Edition IV", | |
"MIR" => "Mirage", | |
"MMA" => "Modern Masters", | |
"MMQ" => "Mercadian Masques", | |
"MOR" => "Morningtide", | |
"MRD" => "Mirrodin", | |
"NEM" => "Nemesis", | |
"NPH" => "New Phyrexia", | |
"ODY" => "Odyssey", | |
"ONS" => "Onslaught", | |
"DDI" => "Duel Decks: Venser vs. Koth", | |
"PC2" => "Planechase 2012 Edition", | |
"PCY" => "Prophecy", | |
"PD3" => "Graveborn", | |
"PLC" => "Planar Chaos", | |
"PLS" => "Planeshift", | |
"POR" => "Portal", | |
"PRM" => "Promo Cards", | |
"DDE" => "Duel Decks: Phyrexia vs. Coalition", | |
"RAV" => "Ravnica: City of Guilds", | |
"ROE" => "Rise of the Eldrazi", | |
"RTR" => "Return to Ravnica", | |
"SCG" => "Scourge", | |
"SHM" => "Shadowmoor", | |
"SOK" => "Saviors of Kamigawa", | |
"SOM" => "Scars of Mirrodin", | |
"STH" => "Stronghold", | |
"TD0" => "Theme Deck Set", | |
"TD2" => "Mirrodin Pure vs New Phyrexia", | |
"THS" => "Theros", | |
"TMP" => "Tempest", | |
"TOR" => "Torment", | |
"TSB" => 'Time Spiral "Timeshifted"', | |
"TSP" => "Time Spiral", | |
"UDS" => "Urza's Destiny", | |
"UGL" => "Unglued", | |
"ULG" => "Urza's Legacy", | |
"UNH" => "Unhinged", | |
"USG" => "Urza's Saga", | |
"V11" => "From the Vault: Legends", | |
"VAN" => "Vanguard", | |
"VIS" => "Visions", | |
"WCS" => "World Championships", | |
"WTH" => "Weatherlight", | |
"WWK" => "Worldwake", | |
"ZEN" => "Zendikar" } | |
collection = CSV.read('collection.csv', headers: true).map(&:to_h).map do |card| | |
{ 'Card Name' => card['Card Name'], 'Cardset' => SETS[card['Set']] }.tap do |row| | |
if card['Premium'] == 'Yes' | |
row['# Owned'] = 0 | |
row['# Foil Owned'] = card['Online'] | |
else | |
row['# Owned'] = card['Online'] | |
row['# Foil Owned'] = 0 | |
end | |
end | |
end | |
CSV.open('converted_collection.csv', 'wb') do |csv| | |
csv << ['Card Name', 'Cardset', '# Owned', '# Foil Owned'] | |
collection.map do |row| | |
csv << row.values | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment