woo
This commit is contained in:
parent
3b568e5722
commit
694a93b788
File diff suppressed because it is too large
Load Diff
35
main.go
35
main.go
|
@ -195,22 +195,45 @@ func fetchCards(limit, cursor int) ([]*Card, error) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
// Example usage
|
||||
limit := 35
|
||||
cursor := 35
|
||||
const limit = 100
|
||||
var allCards []*Card
|
||||
cursor := 0
|
||||
|
||||
for {
|
||||
cards, err := fetchCards(limit, cursor)
|
||||
if err != nil {
|
||||
logErrorAndExit(err)
|
||||
}
|
||||
|
||||
// Output the cards as pretty JSON
|
||||
prettyData, err := json.MarshalIndent(cards, "", " ")
|
||||
allCards = append(allCards, cards...)
|
||||
|
||||
// If the number of returned cards is less than the limit, we've fetched all cards.
|
||||
if len(cards) < limit {
|
||||
break
|
||||
}
|
||||
|
||||
// Update cursor for the next batch
|
||||
cursor += limit
|
||||
}
|
||||
|
||||
// Write all cards to cards.json in the current working directory
|
||||
file, err := os.Create("cards.json")
|
||||
if err != nil {
|
||||
logErrorAndExit(fmt.Errorf("failed to create cards.json: %w", err))
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
prettyData, err := json.MarshalIndent(allCards, "", " ")
|
||||
if err != nil {
|
||||
logErrorAndExit(fmt.Errorf("failed to marshal pretty JSON: %w", err))
|
||||
}
|
||||
|
||||
fmt.Println(string(prettyData))
|
||||
_, err = file.Write(prettyData)
|
||||
if err != nil {
|
||||
logErrorAndExit(fmt.Errorf("failed to write to cards.json: %w", err))
|
||||
}
|
||||
|
||||
fmt.Println("All cards have been written to cards.json")
|
||||
}
|
||||
|
||||
// setHeaders sets the necessary headers for the HTTP request.
|
||||
|
|
Loading…
Reference in New Issue