Implement importing Delver Lens exports
This commit is contained in:
parent
95f45a98fa
commit
70f0b4d4f7
|
@ -6,8 +6,8 @@ import (
|
|||
"fmt"
|
||||
"os/exec"
|
||||
"sevenkeys/database"
|
||||
"sevenkeys/delverlens"
|
||||
"sevenkeys/logic"
|
||||
"sevenkeys/manabox"
|
||||
)
|
||||
|
||||
var output string
|
||||
|
@ -96,9 +96,14 @@ func MainCliLoop(db *sql.DB) {
|
|||
logic.Check(err)
|
||||
copiesInserted++
|
||||
break
|
||||
case "m", "manabox":
|
||||
case "d", "delverlens":
|
||||
filename := GetStringResponse("Filename:")
|
||||
manabox.ParseManaboxExport(filename)
|
||||
|
||||
cards, err := delverlens.ParseExportFile(filename)
|
||||
logic.Check(err)
|
||||
|
||||
err = logic.ImportDelverLensCards(cards)
|
||||
logic.Check(err)
|
||||
break
|
||||
case "l", "locate":
|
||||
filename := GetStringResponse("Filename:")
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
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
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"sevenkeys/database"
|
||||
"sevenkeys/delverlens"
|
||||
)
|
||||
|
||||
func ImportDelverLensCards(db *sql.DB, cards []delverlens.DelverLensCard, storageAreaId int) error {
|
||||
for _, card := range cards {
|
||||
var cardPrintingId string
|
||||
if card.IsFoil {
|
||||
cardPrintingId = card.ScryfallID + "n"
|
||||
} else {
|
||||
cardPrintingId = card.ScryfallID + "f"
|
||||
}
|
||||
|
||||
cardLocation := database.CardLocation{
|
||||
CardPrintingId: cardPrintingId,
|
||||
StorageAreaId: storageAreaId,
|
||||
}
|
||||
|
||||
StoreCard(cardLocation)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue