It is currently 20 Jun 2018, 15:28
   
Text Size

PowerShell script to download mtggoldfish decks automaticly

Moderators: timmermac, friarsol, Blacksmith, KrazyTheFox, Agetian, 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)

HOW TO INSTALL IT
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
cls
$formats = Read-Host -Prompt '¿Which format do you like to download? (modern, legacy, vintage, standard, pauper, frontier, commander, commander_1v1 or tiny_leaders)'
cls
$prefixname = Read-Host -Prompt 'Set a prefix for the decks names'
cls
$sideboard = "Sideboard"
$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
Write-host "My directory is $dir"


$url = "https://www.mtggoldfish.com/metagame/$formats/full#paper"
echo $url
$html = Invoke-WebRequest $url
$mainDeck = $html.parsedhtml.getElementsByClassName("archetype-tile")
echo $mainDeck.length
$e=0
do{
    $sUrl = "https://www.mtggoldfish.com/archetype/$($mainDeck[$e].id)"
    echo $sUrl
    $shtml = Invoke-WebRequest $sUrl
    $smainDeck = $shtml.parsedhtml.getElementsByTagName("input") | Where{ $_.name -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
        do{
        if ($deck[$n][0] -eq 's'){
            $deckFile = "$deckFile`n[Sideboard]"
        }else{
            $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.
Repeperilka
 
Posts: 4
Joined: 19 Nov 2017, 05:12
Has thanked: 1 time
Been thanked: 2 times

Re: PowerShell script to download mtggoldfish decks automati

Postby siyiye » 05 Dec 2017, 03:15

thx!!!

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

Re: PowerShell script to download mtggoldfish decks automati

Postby 5enza » 19 Jun 2018, 13:05

Great script nice job!
5enza
 
Posts: 60
Joined: 16 May 2014, 01:35
Has thanked: 9 times
Been thanked: 12 times


Return to Forge Decks

Who is online

Users browsing this forum: No registered users and 4 guests


Who is online

In total there are 4 users online :: 0 registered, 0 hidden and 4 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 4 guests

Login Form