TheMathemagicians/sevenkeys/delverlens/delverlens.go

49 lines
755 B
Go

package delverlens
import (
"encoding/csv"
"io"
"os"
)
type DelverLensCard struct {
ScryfallID string
IsFoil bool
}
func ParseExportFile(filename string) ([]DelverLensCard, error) {
var cards []DelverLensCard
file, err := os.Open("/home/viciouscirce/dox/sevenkeys_imports/" + filename)
defer file.Close()
if err != nil {
return cards, err
}
r := csv.NewReader(file)
var isHeader bool = true
for {
record, err := r.Read()
if err == io.EOF {
break
} else if err != nil {
return cards, err
}
// Skip the header line
if isHeader {
isHeader = false
continue
}
card := DelverLensCard{
ScryfallID: record[0],
IsFoil: record[1] == "Foil",
}
cards = append(cards, card)
}
return cards, nil
}