From c812784ed31a941ba3d57386889f07cfb515ccf5 Mon Sep 17 00:00:00 2001 From: "A. Svensson" Date: Fri, 6 Oct 2017 21:09:19 +0200 Subject: [PATCH] Ignores servers with 0 players --- scraper.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scraper.go b/scraper.go index 911786c..c7a02dc 100644 --- a/scraper.go +++ b/scraper.go @@ -116,13 +116,15 @@ func parseEntry(s *goquery.Selection) (ServerEntry, error) { // 2 == because the regexp returns wholestring + matched part // If it's less than 2 we couldn't find a match and if it's greater // than 2 there's multiple matches, which is fishy... - players := 0 - if len(r) == 2 { - p, err := strconv.Atoi(r[1]) - if err != nil { - return ServerEntry{}, err - } - players = p + if len(r) != 2 { + return ServerEntry{}, nil + } + + players, err := strconv.Atoi(r[1]) + // Also ignore empty servers (they'll get updated with 0 players/history + // anyway, in a later stage) + if err != nil || players < 1 { + return ServerEntry{}, err } // Grab and sanitize the server's name