From 309b25f896d368bd723a48c9ebf67fc3ec6b9b4c Mon Sep 17 00:00:00 2001 From: Ronoaldo JLP Date: Sat, 17 Dec 2016 22:42:47 +0000 Subject: [PATCH] Makes client.Mods walk over all mod pages. --- swgohgg/mods.go | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/swgohgg/mods.go b/swgohgg/mods.go index f07c0ec..cc3f138 100644 --- a/swgohgg/mods.go +++ b/swgohgg/mods.go @@ -25,7 +25,7 @@ func (m *Mod) String() string { if m == nil { return "nil mod" } - str := fmt.Sprintf("%s %-18s L%d %d* %v %v", m.ShapeIcon(), m.BonusSet, m.Level, m.Rarity, m.PrimStat, m.SecStat) + str := fmt.Sprintf("%s %s L%d %d* %v %v", m.ShapeIcon(), m.BonusSet, m.Level, m.Rarity, m.PrimStat, m.SecStat) if m.UsingIn != "" { str += " (" + m.UsingIn + ")" } @@ -54,17 +54,17 @@ func (m *Mod) ShapeIcon() string { func (m *Mod) ShapeName() string { switch m.Shape { case "Transmitter": - return "Quadrado " + return "Square" case "Processor": - return "Losango " + return "Diamond" case "Holo-Array": - return "Triangulo" + return "Triangle" case "Data-Bus": - return "Circulo " + return "Circle" case "Receiver": - return "Seta " + return "Arrow" case "Multiplexer": - return "Cruz " + return "Cross" default: return m.Shape } @@ -86,20 +86,29 @@ func (ms ModStat) String() string { type ModCollection []*Mod func (c *Client) Mods() (mods ModCollection, err error) { - url := fmt.Sprintf("https://swgoh.gg/u/%s/mods/", c.profile) - resp, err := c.hc.Get(url) - if err != nil { - return nil, err - } - defer resp.Body.Close() - doc, err := goquery.NewDocumentFromReader(resp.Body) - if err != nil { - return nil, err + page := 1 + for { + url := fmt.Sprintf("https://swgoh.gg/u/%s/mods/?page=%d", c.profile, page) + resp, err := c.hc.Get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + doc, err := goquery.NewDocumentFromReader(resp.Body) + if err != nil { + return nil, err + } + count := 0 + doc.Find(".collection-mod").Each(func(i int, s *goquery.Selection) { + mod := parseMod(s) + mods = append(mods, mod) + count++ + }) + if count < 60 { + break + } + page++ } - doc.Find(".collection-mod").Each(func(i int, s *goquery.Selection) { - mod := parseMod(s) - mods = append(mods, mod) - }) return mods, nil }