matheusfm / futbin

An unofficial command-line tool for Futbin
MIT License
41 stars 5 forks source link

Pagination or getting all records #1

Closed chenei closed 1 year ago

chenei commented 2 years ago

Hey, First of all, thanks for this great tool!

Is there a way to support pagination further than the page flag?

  1. Getting all records from all pages?
  2. Getting the number of pages available for specific commands so we can loop through?

Thanks

matheusfm commented 2 years ago

Hello, @chenei Thanks for your comment and sorry for the delay.

Currently, the futbin API that we call to get and filter players only supports up to the 10th page. As can be seen in the example below:

package main

import (
    "fmt"

    "github.com/matheusfm/futbin/players"
)

func main() {
    playersClient := players.DefaultClient()
    var all []players.Player

    for i := 1; i < 100; i++ {
        fmt.Printf("Page %d...\t", i)
        p, err := playersClient.Get(&players.Options{Page: i})
        if err != nil {
            fmt.Printf("ERROR: %v\n", err)
            break
        }
        fmt.Printf("%d players returned\n", len(p))
        if len(p) <= 0 {
            break
        }
        all = append(all, p...)
    }
    fmt.Printf("Total: %d\n", len(all))
}

Output:

$ go run test.go 
Page 1...       32 players returned
Page 2...       32 players returned
Page 3...       32 players returned
Page 4...       32 players returned
Page 5...       32 players returned
Page 6...       32 players returned
Page 7...       32 players returned
Page 8...       32 players returned
Page 9...       32 players returned
Page 10...      32 players returned
Page 11...      0 players returned
Total: 320

The API is https://www.futbin.org/futbin/api/getFilteredPlayers?page=1