-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
142 lines (135 loc) · 4.51 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
func main() {
// scryfall api: https://scryfall.com/docs/api/cards/search
total, m20 := get(fmt.Sprintf("https://api.scryfall.com/cards/search?q=set:m20"))
// do something with it
_ = total
_ = m20
}
func get(url string) (total int, cards []card) {
response, err := http.Get(url)
if err != nil {
log.Fatalln(err)
}
data, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatalln(err)
}
var search search
err = json.Unmarshal(data, &search)
if err != nil {
log.Fatalln(err)
}
// store them in list/map based on id
cards = append(cards, search.Cards...) // add cards
if search.HasMore {
_, next := get(search.NextPage)
cards = append(cards, next...)
}
return search.TotalCards, cards
}
// cardSearch is the structure of the returned JSON by the card search.
type search struct {
Object string `json:"object"` // will be "list"
TotalCards int `json:"total_cards"`
HasMore bool `json:"has_more"`
NextPage string `json:"next_page"`
Cards []card `json:"data"`
}
// card is represents the data of a card returned by the card search.
type card struct {
Object string `json:"object"` // will be "card"
ID string `json:"id"`
OracleID string `json:"oracle_id"`
MultiverseIDs []int `json:"multiverse_ids"`
TCGPlayerID int `json:"tcgplayer_id"`
Name string `json:"name"`
Lang string `json:"lang"`
ReleasedAt string `json:"released_at"`
URI string `json:"uri"`
ScryfallURI string `json:"scryfall_uri"`
Layout string `json:"layout"`
HighResImage bool `json:"highres_image"`
ImageURIs struct {
Small string `json:"small"`
Normal string `json:"normal"`
Large string `json:"large"`
PNG string `json:"png"`
ArtCrop string `json:"art_crop"`
BorderCrop string `json:"border_crop"`
} `json:"image_uris"`
ManaCost string `json:"mana_cost"`
CMC float64 `json:"cmc"`
TypeLine string `json:"type_line"`
OracleText string `json:"oracle_text"`
Power string `json:"power"`
Toughness string `json:"toughness"`
Colors []string `json:"colors"`
ColorIndicator []string `json:"color_indicator"`
ColorIdentity []string `json:"color_identity"`
Legalities struct {
Standard string `json:"standard"`
Future string `json:"future"`
Modern string `json:"modern"`
Legacy string `json:"legacy"`
Pauper string `json:"pauper"`
Vintage string `json:"vintage"`
Penny string `json:"penny"`
Commander string `json:"commander"`
Brawl string `json:"brawl"`
Duel string `json:"duel"`
Oldschool string `json:"oldschool"`
} `json:"legalities"`
Games []string `json:"games"`
Reserved bool `json:"reserved"`
Foil bool `json:"foil"`
NonFoil bool `json:"nonfoil"`
Oversized bool `json:"oversized"`
Promo bool `json:"promo"`
Reprint bool `json:"reprint"`
Variation bool `json:"variation"`
Set string `json:"set"`
SetName string `json:"set_name"`
SetType string `json:"set_type"`
SetURI string `json:"set_uri"`
SetSearchURI string `json:"set_search_uri"`
ScryfallSetURI string `json:"scryfall_set_uri"`
RulingsURI string `json:"rulings_uri"`
PrintsSearchURI string `json:"prints_search_uri"`
CollectorNumber string `json:"collector_number"`
Digital bool `json:"digital"`
Rarity string `json:"rarity"`
IllustrationID string `json:"illustration_id"`
CardBackID string `json:"card_back_id"`
Artist string `json:"artist"`
BorderColor string `json:"border_color"`
Frame string `json:"frame"`
FullArt bool `json:"full_art"`
Textless bool `json:"textless"`
Booster bool `json:"booster"`
StorySpotlight bool `json:"story_spotlight"`
Prices struct {
USD string `json:"usd"`
USDFoil string `json:"usd_foil"`
EUR string `json:"eur"`
TIX string `json:"tix"`
} `json:"prices"`
RelatedURIs struct {
Gatherer string `json:"gatherer"`
TCGPlayerDecks string `json:"tcgplayer_decks"`
EDHREC string `json:"edhrec"`
MTGTop8 string `json:"mtgtop8"`
} `json:"related_uris"`
PurchaseURIs struct {
TCGPlayer string `json:"tcgplayer"`
CardMarket string `json:"cardmarket"`
CardHoarder string `json:"cardhoarder"`
} `json:"purchase_uris"`
}