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() {
|
func main() {
|
||||||
// Example usage
|
const limit = 100
|
||||||
limit := 35
|
var allCards []*Card
|
||||||
cursor := 35
|
cursor := 0
|
||||||
|
|
||||||
|
for {
|
||||||
cards, err := fetchCards(limit, cursor)
|
cards, err := fetchCards(limit, cursor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logErrorAndExit(err)
|
logErrorAndExit(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output the cards as pretty JSON
|
allCards = append(allCards, cards...)
|
||||||
prettyData, err := json.MarshalIndent(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 {
|
if err != nil {
|
||||||
logErrorAndExit(fmt.Errorf("failed to marshal pretty JSON: %w", err))
|
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.
|
// setHeaders sets the necessary headers for the HTTP request.
|
||||||
|
|
Loading…
Reference in New Issue