fix missing ones
This commit is contained in:
parent
2f77b7f32c
commit
c78c766825
@ -52,6 +52,25 @@ func stringToTime(s primitive.DateTime) string {
|
||||
return time.UnixMilli(int64(s)).Format("2006-01-02")
|
||||
}
|
||||
|
||||
// missing compares two slices and returns slice of differences
|
||||
func missing(a, b []string) []string {
|
||||
type void struct{}
|
||||
// create map with length of the 'a' slice
|
||||
ma := make(map[string]void, len(a))
|
||||
diffs := []string{}
|
||||
// Convert first slice to map with empty struct (0 bytes)
|
||||
for _, ka := range a {
|
||||
ma[ka] = void{}
|
||||
}
|
||||
// find missing values in a
|
||||
for _, kb := range b {
|
||||
if _, ok := ma[kb]; !ok {
|
||||
diffs = append(diffs, kb)
|
||||
}
|
||||
}
|
||||
return diffs
|
||||
}
|
||||
|
||||
func find_set_by_code(coll *Collection, setcode string) (*Set, error) {
|
||||
|
||||
stored_sets, err := coll.storage_find_set(bson.D{{"code", setcode}}, bson.D{{"_id", 1}})
|
||||
|
||||
@ -180,34 +180,28 @@ func Missing(setname string) error {
|
||||
set := sets[0]
|
||||
|
||||
LogMessage(fmt.Sprintf("Missing cards in %s", sets[0].Name), "green")
|
||||
|
||||
// generate set with all setnumbers
|
||||
var complete_set []string
|
||||
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
|
||||
for i = 1; i <= set.CardCount; i++ {
|
||||
complete_set = append(complete_set, strconv.FormatInt(i, 10))
|
||||
}
|
||||
|
||||
// iterate over all cards in collection
|
||||
var in_collection []string
|
||||
for _, c := range cards {
|
||||
found = false
|
||||
// check if current card has collector number that we look for
|
||||
if c.CollectorNumber == strconv.FormatInt(i, 16) {
|
||||
in_collection = append(in_collection, c.CollectorNumber)
|
||||
}
|
||||
|
||||
// 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)))
|
||||
misses := missing(in_collection, complete_set)
|
||||
for _, m := range misses {
|
||||
ncard, err := fetch_card(fmt.Sprintf("%s/%s", setname, m))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Printf("%s (%s)\n", ncard.Name, ncard.SetName)
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user