It is currently 24 Mar 2018, 04:08
Text Size

PowerShell script to download mtggoldfish decks automaticly

Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins

PowerShell script to download mtggoldfish decks automaticly

Postby Repeperilka » 28 Nov 2017, 15:53

Hello there.
I want to share with you a little script I made that downlads decks from the metagame page of mtggoldfish and creates a .dck file ready to be played in Forge.

DISCLAIMER: If you want to run it on a pc that is not Win10, you'll have to download PowerShell 3.0 (and I don't know how to do it, so this tuto will be for Windows 10 users)

1: Search in your system (or ask Cortana) for a application called "Windows PowerShell ISE", and run it.
2: In the down window with a blue background type "Set-ExecutionPolicy RemoteSigned"(without "") and press Enter. This will only let you run scripts created by your pc, to prevent other people to run scripts you dont want.
3: In the white window where you can type, copy this:
Code: Select all
$formats = Read-Host -Prompt '¿Which format do you like to download? (modern, legacy, vintage, standard, pauper, frontier, commander, commander_1v1 or tiny_leaders)'
$prefixname = Read-Host -Prompt 'Set a prefix for the decks names'
$sideboard = "Sideboard"
$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
Write-host "My directory is $dir"

$url = "$formats/full#paper"
echo $url
$html = Invoke-WebRequest $url
$mainDeck = $html.parsedhtml.getElementsByClassName("archetype-tile")
echo $mainDeck.length
    $sUrl = "$($mainDeck[$e].id)"
    echo $sUrl
    $shtml = Invoke-WebRequest $sUrl
    $smainDeck = $shtml.parsedhtml.getElementsByTagName("input") | Where{ $ -eq "deck_input[deck]" }
    $deck = $smainDeck.value
    $deck = $deck -split '\n'
    $nmainDeck = $shtml.parsedhtml.getElementsByClassName("deck-view-title")
    $nname = $nmainDeck[0].innerText
    $fullname = $nname.Substring(0,$nname.Length-23)
    $fullname = $fullname.replace("/", "")
    $tfullname = "$prefixname $fullname"
    $deckFile = "[metadata]`nName=$tfullname`n[Main]"
        $n =0
        if ($deck[$n][0] -eq 's'){
            $deckFile = "$deckFile`n[Sideboard]"
            $deckFile = "$deckFile`n$($deck[$n])"
        $n +=1
    }while($n -le $deck.Length - 2)
    $deckFile = $deckFile.ToString()
    $deckFile | Out-File "$dir\$tfullname.dck" -encoding ascii
    $e += 1
}while ($e -le $mainDeck.length)
4: Save it by clicking on the little disk drive on top, the folder where you've saved it is where all the downloaded deck will be created.

HOW TO USE IT1: Right click the archive you've just created, and select "run with Powershell"
2: It will ask you for a format, you just have to type the format you want like it says in the parenthesis, but only one of them. Then press Enter.
3: Now you can type a prefix and press Enter, for example if I type "GF metagame" (without "") and I'm downloading a deck called "Affinity", the final name of the deck will be "GF metagame Affinity"
4: Sit down and let it do its magic. When the script is over, it will close automaticly.
Posts: 4
Joined: 19 Nov 2017, 05:12
Has thanked: 1 time
Been thanked: 1 time

Re: PowerShell script to download mtggoldfish decks automati

Postby siyiye » 05 Dec 2017, 03:15


Nice script!
Posts: 9
Joined: 09 Sep 2014, 12:19
Has thanked: 0 time
Been thanked: 0 time

Return to Forge Decks

Who is online

Users browsing this forum: No registered users and 5 guests

Who is online

In total there are 5 users online :: 0 registered, 0 hidden and 5 guests (based on users active over the past 10 minutes)
Most users ever online was 279 on 11 Jul 2013, 22:03

Users browsing this forum: No registered users and 5 guests

Login Form