-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_card.go
47 lines (35 loc) · 880 Bytes
/
fetch_card.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
package main
import (
"fmt"
"log"
"sync"
"time"
"github.com/PuerkitoBio/goquery"
)
func GetCard(url string, wg *sync.WaitGroup) Card {
defer wg.Done()
doc, err := goquery.NewDocument(url)
if err != nil {
log.Fatal(err)
}
card := ParseCard(doc)
fmt.Printf("Name: %s\t\tType: %s, ID: %s\n", card.Name(), card.Type(), card.Id())
return card
}
func main() {
var url string
//var card Card
var wg sync.WaitGroup
for _, expansion := range Expansions() {
fmt.Println("Processing: ", expansion.Name())
wg.Add(expansion.Count())
for i := 1; i <= expansion.Count(); i++ {
url = fmt.Sprintf("http://www.pokemon.com/us/pokemon-tcg/pokemon-cards/%s/%s/%d/",
expansion.Series(), expansion.Id(), i)
go GetCard(url, &wg)
}
wg.Wait()
// Pokemon.com fails if you hit it too agressively so backoff between sets
time.Sleep(15 * time.Second)
}
}