TheMathemagicians/sevenkeys/delverlens/delverlens.go

51 lines
835 B
Go
Raw Normal View History

package delverlens
import (
"encoding/csv"
"io"
"os"
"strings"
)
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)
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{
Name: record[0],
IsFoil: record[1] == "Foil",
CollectorNumber: record[2],
SetCode: strings.ToLower(record[3]),
}
cards = append(cards, card)
}
return cards, nil
}