filter for cards
This commit is contained in:
parent
05706f2a35
commit
9bf62ff6cd
7
serra.go
7
serra.go
@ -20,8 +20,9 @@ var opts struct {
|
||||
Stats bool `docopt:"stats"`
|
||||
Update bool `docopt:"update"`
|
||||
CardId []string `docopt:"<cardid>"`
|
||||
SetCode string `docopt:"<setcode>"`
|
||||
SetCode string `docopt:"<setcode>,--set"`
|
||||
Count int64 `docopt:"--count"`
|
||||
Rarity string `docopt:"--rarity"`
|
||||
}
|
||||
|
||||
// Main Loop
|
||||
@ -32,7 +33,7 @@ func main() {
|
||||
Usage:
|
||||
serra add <cardid>... [--count=<number>]
|
||||
serra remove <cardid>...
|
||||
serra cards
|
||||
serra cards [--rarity=<rarity>] [--set=<setcode>]
|
||||
serra card <cardid>...
|
||||
serra set <setcode>
|
||||
serra sets
|
||||
@ -57,7 +58,7 @@ Options:
|
||||
} else if opts.Remove {
|
||||
serra.Remove(opts.CardId)
|
||||
} else if opts.Cards {
|
||||
serra.Cards()
|
||||
serra.Cards(opts.Rarity, opts.SetCode)
|
||||
} else if opts.Card {
|
||||
serra.ShowCard(opts.CardId)
|
||||
} else if opts.Sets {
|
||||
|
||||
@ -68,6 +68,8 @@ func find_set_by_code(coll *Collection, setcode string) (*Set, error) {
|
||||
func show_card_details(card *Card) error {
|
||||
fmt.Printf("* %dx %s%s%s (%s/%s)\n", card.SerraCount, Purple, card.Name, Reset, card.Set, card.CollectorNumber)
|
||||
fmt.Printf(" Added: %s\n", stringToTime(card.SerraCreated))
|
||||
fmt.Printf(" Rarity: %s\n", card.Rarity)
|
||||
fmt.Printf(" Scryfall: %s\n", card.ScryfallURI)
|
||||
fmt.Printf(" Current Value: %s%.2f EUR%s\n", Yellow, card.Prices.Eur, Reset)
|
||||
fmt.Printf(" History:\n")
|
||||
for _, e := range card.SerraPrices {
|
||||
|
||||
@ -79,13 +79,28 @@ func Remove(cards []string) {
|
||||
}
|
||||
}
|
||||
|
||||
func Cards() {
|
||||
func Cards(rarity, set string) {
|
||||
|
||||
client := storage_connect()
|
||||
coll := &Collection{client.Database("serra").Collection("cards")}
|
||||
defer storage_disconnect(client)
|
||||
|
||||
cards, _ := coll.storage_find(bson.D{{}}, bson.D{{"name", 1}})
|
||||
filter := bson.D{}
|
||||
|
||||
switch rarity {
|
||||
case "uncommon":
|
||||
filter = append(filter, bson.E{"rarity", "uncommon"})
|
||||
case "common":
|
||||
filter = append(filter, bson.E{"rarity", "common"})
|
||||
case "rare":
|
||||
filter = append(filter, bson.E{"rarity", "rare"})
|
||||
}
|
||||
|
||||
if len(set) > 0 {
|
||||
filter = append(filter, bson.E{"set", set})
|
||||
}
|
||||
|
||||
cards, _ := coll.storage_find(filter, bson.D{{"name", 1}})
|
||||
|
||||
for _, card := range cards {
|
||||
LogMessage(fmt.Sprintf("* %dx %s%s%s (%s/%s) %s%.2f EUR%s", card.SerraCount, Purple, card.Name, Reset, card.Set, card.CollectorNumber, Yellow, card.Prices.Eur, Reset), "normal")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user