Created
November 25, 2022 12:50
-
-
Save Mikulas/e25265acd261662e7e0ec1b308e8c85f to your computer and use it in GitHub Desktop.
Convert Lion's Eye Plain Text into Moxfield compatible deckstats.net CSV
This file contains 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
package main | |
import ( | |
"fmt" | |
"github.com/tushar2708/altcsv" | |
"log" | |
"os" | |
"strconv" | |
"strings" | |
) | |
const ( | |
CName = iota | |
CSet | |
CCollectorNumber | |
CLanguage | |
CNonFoilCount | |
CFoilCount | |
CFavorite | |
CScryfallID | |
) | |
func main() { | |
f, err := os.Open("export.csv") | |
if err != nil { | |
log.Fatal(err.Error()) | |
} | |
defer f.Close() | |
csvReader := altcsv.NewReader(f) | |
records, err := csvReader.ReadAll() | |
if err != nil { | |
log.Fatal(err.Error()) | |
} | |
deckstatsnet(records) | |
} | |
func deckstatsnet(records [][]string) { | |
fo, err := os.OpenFile("deckstatsnet.csv", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666) | |
if err != nil { | |
log.Fatal(err.Error()) | |
} | |
defer fo.Close() | |
csvwriter := altcsv.NewWriter(fo) | |
csvwriter.AllQuotes = true | |
csvwriter.Write([]string{"amount", "card_name", "is_foil", "set_code", "collector_number"}) | |
for _, record := range records[1:] { | |
nonFoilCount, _ := strconv.Atoi(strings.TrimSpace(record[CNonFoilCount])) | |
foilCount, _ := strconv.Atoi(strings.TrimSpace(record[CFoilCount])) | |
if nonFoilCount > 0 { | |
csvwriter.Write([]string{ | |
fmt.Sprintf("%d", nonFoilCount), | |
strings.TrimSpace(record[CName]), | |
"", | |
strings.TrimSpace(record[CSet]), | |
strings.TrimSpace(record[CCollectorNumber]), | |
}) | |
} | |
if foilCount > 0 { | |
csvwriter.Write([]string{ | |
fmt.Sprintf("%d", foilCount), | |
strings.TrimSpace(record[CName]), | |
"1", | |
strings.TrimSpace(record[CSet]), | |
strings.TrimSpace(record[CCollectorNumber]), | |
}) | |
} | |
} | |
csvwriter.Flush() | |
} |
This file contains 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
module moxfield | |
go 1.19 | |
require github.com/tushar2708/altcsv v0.0.0-20190930232535-20830d2e2c68 // indirect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Import at https://www.moxfield.com/collection as “deckstats.net”