collectornumber is now a number

This commit is contained in:
Florian Baumann 2022-01-03 16:22:34 +01:00
parent 9ddb187eea
commit 7f88d6a6f4
5 changed files with 38 additions and 3 deletions

8
f Normal file
View File

@ -0,0 +1,8 @@
for x in (seq 1 360 ) ; echo 4ed/$x ; end | xargs ./serra add
for x in (seq 11 140 ) ; echo unh/$x ; end | xargs ./serra add
for x in (seq 1 9 ) ; echo unh/$x ; end | xargs ./serra add
./serra add tugl/1
for x in (seq 71 89) ; echo ugl/$x ; end | xargs ./serra add
for x in (seq 1 69) ; echo ugl/$x ; end | xargs ./serra add
for x in (seq 251 350) ; echo mmq/$x ; end | xargs ./serra add
for x in (seq 4 250) ; echo mmq/$x ; end | xargs ./serra add

BIN
serra

Binary file not shown.

View File

@ -14,6 +14,7 @@ func main() {
Usage:
serra add <card>...
serra cards
serra set <set>
serra sets
serra update
@ -30,6 +31,8 @@ Options:
serra.Cards()
} else if args["sets"].(bool) {
serra.Sets()
} else if args["set"].(bool) {
serra.ShowSet(args["<set>"].(string))
} else if args["update"].(bool) {
serra.Update()
}

View File

@ -88,6 +88,30 @@ func Sets() {
}
func ShowSet(setname string) error {
LogMessage(fmt.Sprintf("Serra %v\n", version), "green")
client := storage_connect()
coll := &Collection{client.Database("serra").Collection("cards")}
sort := bson.D{{"collectornumber", 1}}
filter := bson.D{{"set", setname}}
cards, err := coll.storage_find(filter, sort)
if (err != nil) || len(cards) == 0 {
LogMessage(fmt.Sprintf("Error: Set %s not found or no card in your collection.", setname), "red")
return err
}
// print
fmt.Printf("%s\n", cards[0].SetName)
for _, card := range cards {
fmt.Printf("%dx %d %s %.2f\n", card.SerraCount, card.CollectorNumber, card.Name, card.Prices.Eur)
}
storage_disconnect(client)
return nil
}
func Update() {
LogMessage(fmt.Sprintf("Serra %v\n", version), "green")

View File

@ -26,7 +26,7 @@ type Card struct {
BorderColor string `json:"border_color"`
CardBackID string `json:"card_back_id"`
Cmc int64 `json:"cmc"`
CollectorNumber string `json:"collector_number"`
CollectorNumber int64 `json:"collector_number,string"`
ColorIdentity []string `json:"color_identity"`
Colors []string `json:"colors"`
Digital bool `json:"digital"`
@ -156,7 +156,7 @@ func fetch_card(path string) (*Card, error) {
}
if resp.StatusCode != 200 {
err := errors.New(fmt.Sprintf("card: %s not found", path))
err := errors.New(fmt.Sprintf("Error: %s not found", path))
return &Card{}, err
}
@ -193,7 +193,7 @@ func fetch_set(path string) (*Set, error) {
}
if resp.StatusCode != 200 {
err := errors.New(fmt.Sprintf("set: %s not found", path))
err := errors.New(fmt.Sprintf("Error: %s not found", path))
return &Set{}, err
}