Guest User

Scryfall Set to Deckbox CSV

a guest
Jun 14th, 2021
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $set = "mh2"
  2. $nextUri = "https://api.scryfall.com/cards/search?q=s:$set&order=set&unique=prints"
  3. $loadedSets = @{}
  4. $csv = @()
  5. while ($nextUri) {
  6.     Write-Host "Loading batch... " -NoNewline
  7.     $jsonData = ConvertFrom-Json (Invoke-WebRequest -Uri $nextUri).Content
  8.     Write-Host "$($jsonData.data.Count) results"
  9.     $jsonData.data | ForEach-Object {
  10.         if (-not ($_.set -in $loadedSets.Keys)) {
  11.             Write-Host "Found uncached set: $($_.set). Loading data..."
  12.             $setJson = ConvertFrom-Json (Invoke-WebRequest -Uri "https://api.scryfall.com/sets/$($_.set)").Content
  13.             $loadedSets[$_.set] = $setJson.name
  14.         }
  15.         $csv += [PSCustomObject]@{
  16.             "Count" = 0
  17.             "Tradelist Count" = 0
  18.             "Name" = $_.name
  19.             "Edition" = $loadedSets[$_.set]
  20.             "Card Number" = $_.collector_number
  21.             "Condition" = "Near Mint"
  22.             "Language" = "English"
  23.             "Foil" = ""
  24.             "Signed" = ""
  25.             "Artist Proof" = ""
  26.             "Altered Art" = ""
  27.             "Misprint" = ""
  28.             "Promo" = ""
  29.             "Textless" = ""
  30.             "Price" = $_.prices.usd
  31.             "Foil Price" = $_.prices.usd_foil
  32.         }
  33.     }
  34.     $nextUri = $jsonData.next_page
  35. }
  36.  
  37. Clear-Content ".\mtg-out.csv"
  38. $csv | Export-Csv ".\mtg-out.csv" -NoTypeInformation
  39.  
Advertisement
Add Comment
Please, Sign In to add comment