Add export to tcghome and moxfield
This commit is contained in:
parent
51e139a964
commit
7ad859704d
@ -1,8 +1,11 @@
|
|||||||
package serra
|
package serra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/csv"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -38,6 +41,10 @@ var exportCmd = &cobra.Command{
|
|||||||
switch format {
|
switch format {
|
||||||
case "tcgpowertools":
|
case "tcgpowertools":
|
||||||
exportTCGPowertools(cardList)
|
exportTCGPowertools(cardList)
|
||||||
|
case "tcghome":
|
||||||
|
exportTCGHome(cardList)
|
||||||
|
case "moxfield":
|
||||||
|
exportMoxfield(cardList)
|
||||||
case "json":
|
case "json":
|
||||||
exportJson(cardList)
|
exportJson(cardList)
|
||||||
}
|
}
|
||||||
@ -58,6 +65,62 @@ func exportTCGPowertools(cards []Card) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func exportMoxfield(cards []Card) {
|
||||||
|
|
||||||
|
// Structure
|
||||||
|
// https://www.moxfield.com/help/importing-collection
|
||||||
|
|
||||||
|
records := [][]string{{
|
||||||
|
"Count", "Name", "Edition", "Condition", "Language", "Foil", "Collector Number", "Alter", "Proxy", "Purchase Price"}}
|
||||||
|
|
||||||
|
w := csv.NewWriter(os.Stdout)
|
||||||
|
|
||||||
|
for _, card := range cards {
|
||||||
|
records = append(records,
|
||||||
|
[]string{fmt.Sprintf("%d", card.SerraCount), card.Name, card.Set, "NM", "English", "FALSE", card.CollectorNumber, "FALSE", "FALSE", ""})
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, record := range records {
|
||||||
|
if err := w.Write(record); err != nil {
|
||||||
|
log.Fatalln("error writing record to csv:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
|
||||||
|
if err := w.Error(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func exportTCGHome(cards []Card) {
|
||||||
|
|
||||||
|
// Strucutre
|
||||||
|
// https://app.tcg-home.com/e686ea62-7078-4f52-bd6f-515e18c7dc6a
|
||||||
|
|
||||||
|
records := [][]string{{
|
||||||
|
"amount", "name", "finish", "set", "collector_number", "language", "condition", "scryfall_id", "purchase_price"}}
|
||||||
|
|
||||||
|
w := csv.NewWriter(os.Stdout)
|
||||||
|
|
||||||
|
for _, card := range cards {
|
||||||
|
records = append(records,
|
||||||
|
[]string{fmt.Sprintf("%d", card.SerraCount), card.Name, "", card.Set, card.CollectorNumber, "English", "EX", card.ID, ""})
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, record := range records {
|
||||||
|
if err := w.Write(record); err != nil {
|
||||||
|
log.Fatalln("error writing record to csv:", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
|
||||||
|
if err := w.Error(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func exportJson(cards []Card) {
|
func exportJson(cards []Card) {
|
||||||
ehj, _ := json.MarshalIndent(cards, "", " ")
|
ehj, _ := json.MarshalIndent(cards, "", " ")
|
||||||
fmt.Println(string(ehj))
|
fmt.Println(string(ehj))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user