Add export function
This commit is contained in:
parent
c7052c9aec
commit
0b72fa0265
44
src/serra/export.go
Normal file
44
src/serra/export.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package serra
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
exportCmd.Flags().StringVarP(&set, "set", "e", "", "Filter by set code (usg/mmq/vow)")
|
||||||
|
exportCmd.Flags().StringVarP(&format, "format", "f", "tcgpowertools", "Choose format to export (tcgpowertools)")
|
||||||
|
rootCmd.AddCommand(exportCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var exportCmd = &cobra.Command{
|
||||||
|
Use: "export",
|
||||||
|
Short: "Export cards from your collection",
|
||||||
|
Long: `Search and show cards from your collection.
|
||||||
|
If you directly put a card as an argument, it will be displayed
|
||||||
|
otherwise you'll get a list of cards as a search result.`,
|
||||||
|
SilenceErrors: true,
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
cardList := Cards(rarity, set, sortby, name, oracle, cardType, reserved, foil, 0, 0)
|
||||||
|
|
||||||
|
switch format {
|
||||||
|
case "tcgpowertools":
|
||||||
|
exportTCGPowertools(cardList)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func exportTCGPowertools(cards []Card) {
|
||||||
|
|
||||||
|
// TCGPowertools.com Example
|
||||||
|
// idProduct,quantity,name,set,condition,language,isFoil,isPlayset,isSigned,isFirstEd,price,comment
|
||||||
|
// 260009,1,Totally Lost,Gatecrash,GD,English,true,true,,,1000,
|
||||||
|
// 260009,1,Totally Lost,Gatecrash,NM,English,true,true,,,1000,
|
||||||
|
|
||||||
|
fmt.Println("idProduct,quantity,name,set,condition,language,isFoil,isPlayset,isSigned,isFirstEd,price,comment")
|
||||||
|
for _, card := range cards {
|
||||||
|
fmt.Printf("%s,%d,%s,%s,EX,German,false,false,,,%.2f,,\n", card.CardmarketID, card.SerraCount, card.Name, card.SetName, card.getValue(false))
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,6 +11,7 @@ var (
|
|||||||
count int64
|
count int64
|
||||||
detail bool
|
detail bool
|
||||||
foil bool
|
foil bool
|
||||||
|
format string
|
||||||
interactive bool
|
interactive bool
|
||||||
limit float64
|
limit float64
|
||||||
name string
|
name string
|
||||||
|
|||||||
@ -26,6 +26,7 @@ type Card struct {
|
|||||||
Booster bool `json:"booster"`
|
Booster bool `json:"booster"`
|
||||||
BorderColor string `json:"border_color"`
|
BorderColor string `json:"border_color"`
|
||||||
CardBackID string `json:"card_back_id"`
|
CardBackID string `json:"card_back_id"`
|
||||||
|
CardmarketID string `json:"cardmarket_id"`
|
||||||
Cmc float64 `json:"cmc"`
|
Cmc float64 `json:"cmc"`
|
||||||
CollectorNumber string `json:"collector_number"`
|
CollectorNumber string `json:"collector_number"`
|
||||||
ColorIdentity []string `json:"color_identity"`
|
ColorIdentity []string `json:"color_identity"`
|
||||||
@ -112,6 +113,7 @@ type Card struct {
|
|||||||
SetURI string `json:"set_uri"`
|
SetURI string `json:"set_uri"`
|
||||||
StorySpotlight bool `json:"story_spotlight"`
|
StorySpotlight bool `json:"story_spotlight"`
|
||||||
Textless bool `json:"textless"`
|
Textless bool `json:"textless"`
|
||||||
|
TCGPlayerID string `json:"tcgplayer_id"`
|
||||||
TypeLine string `json:"type_line"`
|
TypeLine string `json:"type_line"`
|
||||||
URI string `json:"uri"`
|
URI string `json:"uri"`
|
||||||
Variation bool `json:"variation"`
|
Variation bool `json:"variation"`
|
||||||
|
|||||||
@ -89,7 +89,7 @@ var updateCmd = &cobra.Command{
|
|||||||
updatedCard.Prices.Date = primitive.NewDateTimeFromTime(time.Now())
|
updatedCard.Prices.Date = primitive.NewDateTimeFromTime(time.Now())
|
||||||
|
|
||||||
update := bson.M{
|
update := bson.M{
|
||||||
"$set": bson.M{"serra_updated": primitive.NewDateTimeFromTime(time.Now()), "prices": updatedCard.Prices, "cmc": updatedCard.Cmc},
|
"$set": bson.M{"serra_updated": primitive.NewDateTimeFromTime(time.Now()), "prices": updatedCard.Prices, "cmc": updatedCard.Cmc, "cardmarket_id": updatedCard.CardmarketID, "tcgplayer_id": updatedCard.TCGPlayerID},
|
||||||
"$push": bson.M{"serra_prices": updatedCard.Prices},
|
"$push": bson.M{"serra_prices": updatedCard.Prices},
|
||||||
}
|
}
|
||||||
coll.storageUpdate(bson.M{"_id": bson.M{"$eq": card.ID}}, update)
|
coll.storageUpdate(bson.M{"_id": bson.M{"$eq": card.ID}}, update)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user