missing feature with bugs

This commit is contained in:
Florian Baumann 2022-01-10 08:09:40 +01:00
parent a65e3e9c81
commit 29a51bce02
2 changed files with 55 additions and 0 deletions

View File

@ -18,6 +18,7 @@ var opts struct {
Set bool `docopt:"set"`
Sets bool `docopt:"sets"`
Stats bool `docopt:"stats"`
Missing bool `docopt:"missing"`
Update bool `docopt:"update"`
CardId []string `docopt:"<cardid>"`
SetCode string `docopt:"<setcode>,--set"`
@ -35,6 +36,7 @@ Usage:
serra remove <cardid>...
serra cards [--rarity=<rarity>] [--set=<setcode>]
serra card <cardid>...
serra missing <setcode>
serra set <setcode>
serra sets
serra update
@ -63,6 +65,8 @@ Options:
serra.ShowCard(opts.CardId)
} else if opts.Sets {
serra.Sets()
} else if opts.Missing {
serra.Missing(opts.SetCode)
} else if opts.Set {
serra.ShowSet(opts.SetCode)
} else if opts.Update {

View File

@ -2,6 +2,7 @@ package serra
import (
"fmt"
"strconv"
"strings"
"time"
@ -156,6 +157,56 @@ func Sets() {
}
func Missing(setname string) error {
client := storage_connect()
coll := &Collection{client.Database("serra").Collection("cards")}
defer storage_disconnect(client)
// fetch all cards in set
cards, err := coll.storage_find(bson.D{{"set", setname}}, bson.D{{"collectornumber", 1}})
if (err != nil) || len(cards) == 0 {
LogMessage(fmt.Sprintf("Error: Set %s not found or no card in your collection.", setname), "red")
return err
}
// fetch set informations
setcoll := &Collection{client.Database("serra").Collection("sets")}
sets, _ := setcoll.storage_find_set(bson.D{{"code", setname}}, bson.D{{"_id", 1}})
set := sets[0]
LogMessage(fmt.Sprintf("Missing cards in %s", sets[0].Name), "green")
var i int64
// iterate over all cards in set
for i = 1; i < set.CardCount; i++ {
fmt.Printf("Checking usg/%d\n", i)
var found bool
found = false
// iterate over all cards in collection
for _, c := range cards {
found = false
// check if current card has collector number that we look for
if c.CollectorNumber == strconv.FormatInt(i, 16) {
// if yes, set found to true, and stop looking
found = true
break
}
}
if !found {
ncard, err := fetch_card(fmt.Sprintf("%s/%s", setname, strconv.FormatInt(i, 16)))
if err != nil {
continue
}
fmt.Printf("%s (%s)\n", ncard.Name, ncard.SetName)
}
}
return nil
}
func ShowSet(setname string) error {
client := storage_connect()