This commit is contained in:
Jeffrey Paul 2024-05-20 04:27:02 -07:00
parent 3b568e5722
commit 694a93b788
2 changed files with 80494 additions and 21 deletions

80450
cards.json Normal file

File diff suppressed because it is too large Load Diff

35
main.go
View File

@ -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.