Skip to content

Commit

Permalink
update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianojn committed Oct 15, 2015
1 parent 4ee318b commit bd168d6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions rulings.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ func getRulings() {
if i%100 == 0 {
fmt.Println(i, "of", size)
}
id, text := getRuling(page)
id, text, err := getRuling(page)

if (id != "") && (text != "") {
if err == nil {
result[id] = stripRulingText(text)
}
}

save(result, *ruling)
}

func getRuling(page string) (cardId, cardText string) {
func getRuling(page string) (cardId, cardText string, err error) {
resp, err := http.PostForm("http://yugioh.wikia.com/api.php",
url.Values{
"action": {"query"},
Expand All @@ -55,7 +55,7 @@ func getRuling(page string) (cardId, cardText string) {
})
if err != nil {
fmt.Println(page, err)
return
return "", "", err
}
var data struct {
Query struct {
Expand All @@ -70,12 +70,12 @@ func getRuling(page string) (cardId, cardText string) {
err = json.NewDecoder(resp.Body).Decode(&data)
if err != nil {
fmt.Println(page, err)
return
return "", "", err
}

for _, p := range data.Query.Pages {
if p.Revisions == nil {
return
return "", "", err
}
if p.Ns == 102 {
cardText = p.Revisions[0].Text
Expand All @@ -84,7 +84,7 @@ func getRuling(page string) (cardId, cardText string) {
cardId = extractNumber(p.Revisions[0].Text)
}
}
return
return cardText, cardId, nil
}

var removalList = []*regexp.Regexp{
Expand Down

0 comments on commit bd168d6

Please sign in to comment.