2024-09-23 21:03:31 +00:00
|
|
|
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)
|
2024-09-25 11:03:35 +00:00
|
|
|
defer file.Close()
|
2024-09-23 21:03:31 +00:00
|
|
|
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{
|
2024-09-25 10:48:01 +00:00
|
|
|
ScryfallID: record[0],
|
|
|
|
IsFoil: record[1] == "Foil",
|
2024-09-23 21:03:31 +00:00
|
|
|
}
|
|
|
|
cards = append(cards, card)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cards, nil
|
|
|
|
}
|