woo
This commit is contained in:
parent
3b568e5722
commit
694a93b788
File diff suppressed because it is too large
Load Diff
65
main.go
65
main.go
|
@ -10,11 +10,11 @@ import (
|
||||||
|
|
||||||
// Card represents the structure of a card in the API response.
|
// Card represents the structure of a card in the API response.
|
||||||
type Card struct {
|
type Card struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Hotscore int `json:"hotscore"`
|
Hotscore int `json:"hotscore"`
|
||||||
Guardian Guardian `json:"guardian"`
|
Guardian Guardian `json:"guardian"`
|
||||||
Elements []Element `json:"elements"`
|
Elements []Element `json:"elements"`
|
||||||
Variants []Variant `json:"variants"`
|
Variants []Variant `json:"variants"`
|
||||||
}
|
}
|
||||||
|
@ -60,11 +60,11 @@ type Variant struct {
|
||||||
|
|
||||||
// SetCard represents the structure of a set card in the card details.
|
// SetCard represents the structure of a set card in the card details.
|
||||||
type SetCard struct {
|
type SetCard struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
SetID string `json:"setId"`
|
SetID string `json:"setId"`
|
||||||
CardID string `json:"cardId"`
|
CardID string `json:"cardId"`
|
||||||
Meta MetaData `json:"meta"`
|
Meta MetaData `json:"meta"`
|
||||||
SetDetails SetDetails `json:"set"`
|
SetDetails SetDetails `json:"set"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,8 +89,8 @@ type MetaData struct {
|
||||||
|
|
||||||
// SetDetails represents the structure of set details in the set card.
|
// SetDetails represents the structure of set details in the set card.
|
||||||
type SetDetails struct {
|
type SetDetails struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
ReleaseDate string `json:"releaseDate"`
|
ReleaseDate string `json:"releaseDate"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
||||||
cards, err := fetchCards(limit, cursor)
|
for {
|
||||||
if err != nil {
|
cards, err := fetchCards(limit, cursor)
|
||||||
logErrorAndExit(err)
|
if err != nil {
|
||||||
|
logErrorAndExit(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output the cards as pretty JSON
|
// Write all cards to cards.json in the current working directory
|
||||||
prettyData, err := json.MarshalIndent(cards, "", " ")
|
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