From c825f825f8ffaebb21d56b8c64a8adf1cb72203b Mon Sep 17 00:00:00 2001 From: Alain Gilbert Date: Thu, 13 Sep 2018 00:30:16 -0700 Subject: [PATCH] Fix planet activity < 15min --- ogame.go | 8 +++++--- ogame_test.go | 21 +++++++++++++++++++++ samples/galaxy_planet_activity.html | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 samples/galaxy_planet_activity.html diff --git a/ogame.go b/ogame.go index 3921685e..bdb33399 100644 --- a/ogame.go +++ b/ogame.go @@ -1661,9 +1661,11 @@ func extractGalaxyInfos(pageHTML, botPlayerName string, botPlayerID, botPlayerRa activity := 0 activityDiv := s.Find("div.activity") if activityDiv != nil { - activityRaw := strings.TrimSpace(activityDiv.Text()) - if activityRaw != "" { - activity, _ = strconv.Atoi(activityRaw) + activityDivClass := activityDiv.AttrOr("class", "") + if strings.Contains(activityDivClass, "minute15") { + activity = 15 + } else if strings.Contains(activityDivClass, "showMinutes") { + activity, _ = strconv.Atoi(strings.TrimSpace(activityDiv.Text())) } } diff --git a/ogame_test.go b/ogame_test.go index 90421c2b..2b44da60 100644 --- a/ogame_test.go +++ b/ogame_test.go @@ -153,6 +153,27 @@ func TestExtractGalaxyInfosOwnPlanet(t *testing.T) { assert.Equal(t, "Homeworld", infos[4].Name) } +func TestExtractGalaxyInfosPlanetNoActivity(t *testing.T) { + pageHTMLBytes, _ := ioutil.ReadFile("samples/galaxy_planet_activity.html") + infos, _ := extractGalaxyInfos(string(pageHTMLBytes), "Commodore Nomade", 123, 456) + assert.Equal(t, 8, len(infos)) + assert.Equal(t, 0, infos[7].Activity) +} + +func TestExtractGalaxyInfosPlanetActivity15(t *testing.T) { + pageHTMLBytes, _ := ioutil.ReadFile("samples/galaxy_planet_activity.html") + infos, _ := extractGalaxyInfos(string(pageHTMLBytes), "Commodore Nomade", 123, 456) + assert.Equal(t, 8, len(infos)) + assert.Equal(t, 15, infos[2].Activity) +} + +func TestExtractGalaxyInfosPlanetActivity23(t *testing.T) { + pageHTMLBytes, _ := ioutil.ReadFile("samples/galaxy_planet_activity.html") + infos, _ := extractGalaxyInfos(string(pageHTMLBytes), "Commodore Nomade", 123, 456) + assert.Equal(t, 8, len(infos)) + assert.Equal(t, 23, infos[3].Activity) +} + func TestExtractGalaxyInfosMoonActivity(t *testing.T) { pageHTMLBytes, _ := ioutil.ReadFile("samples/galaxy_moon_activity.html") infos, _ := extractGalaxyInfos(string(pageHTMLBytes), "Commodore Nomade", 123, 456) diff --git a/samples/galaxy_planet_activity.html b/samples/galaxy_planet_activity.html new file mode 100644 index 00000000..f8a41a74 --- /dev/null +++ b/samples/galaxy_planet_activity.html @@ -0,0 +1 @@ +{"galaxy":"\n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n Esp.Probe:\n 0<\/span>\n <\/span>\n \n Recy.:\n 0<\/span>\n <\/span>\n \n IPM.:\n 0<\/span>\n <\/span>\n \n Used slots:\n \n 0<\/span>\/14\n <\/span>\n <\/span>\n\n \n E<\/span>\n I<\/span>\n N<\/span>\n A<\/span>\n V<\/span>\n <\/span>\n <\/th>\n <\/tr>\n
Planet<\/th>\n Name<\/th>\n Moon<\/th>\n DF<\/th>\n Player (status)<\/th>\n Alliance<\/th>\n Action<\/th>\n <\/tr>\n <\/thead>\n
\n <\/td>\n <\/tr>\n
\n \n \n <\/span>\n <\/a>\n <\/span>\n 8 Planets colonised<\/span>\n
\n <\/td>\n <\/tr>\n <\/tfoot>\n
1<\/td>\n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n <\/span>\n <\/a>\n <\/td>\n \n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n
\n \"\"\/\n <\/div>\n <\/td>\n
\n \n <\/span>\n \n <\/span>\n <\/td>\n \n <\/td>\n \n \n <\/span>\n <\/td>\n <\/tr>\n
2<\/td>\n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n <\/span>\n <\/a>\n <\/td>\n \n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n
\n \"\"\/\n <\/div>\n <\/td>\n
\n \n <\/span>\n \n <\/span>\n <\/td>\n \n <\/td>\n \n \n <\/span>\n <\/td>\n <\/tr>\n
3<\/td>\n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n <\/span>\n <\/a>\n <\/td>\n \n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n
\n \"\"\/\n <\/div>\n <\/td>\n
\n \n <\/span>\n \n <\/span>\n <\/td>\n \n <\/td>\n \n \n <\/span>\n <\/td>\n <\/tr>\n
4<\/td>\n \n \n kiedys cie ...\n <\/td>\n \n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n
\n \"\"\/\n <\/div>\n <\/td>\n
\n \n Tarkin<\/span>\n <\/a>\n \n (v<\/span><\/span> I<\/span><\/span>)\n <\/span>\n \n \n POL\n \n \n \n <\/span>\n <\/a>\n <\/span><\/a>\n \n <\/span>\n <\/a>\n \n <\/span>\n <\/span>\n \n <\/span>\n <\/td>\n <\/tr>\n
5<\/td>\n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n <\/span>\n <\/a>\n <\/td>\n \n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n
\n \"\"\/\n <\/div>\n <\/td>\n
\n \n <\/span>\n \n <\/span>\n <\/td>\n \n <\/td>\n \n \n <\/span>\n <\/td>\n <\/tr>\n
6<\/td>\n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n <\/span>\n <\/a>\n <\/td>\n \n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n
\n \"\"\/\n <\/div>\n <\/td>\n
\n \n <\/span>\n \n <\/span>\n <\/td>\n \n <\/td>\n \n \n <\/span>\n <\/td>\n <\/tr>\n
7<\/td>\n \n \n xxx\n <\/td>\n \n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n
\n \"\"\/\n <\/div>\n <\/td>\n
\n \n Tarkin<\/span>\n <\/a>\n \n (v<\/span><\/span> I<\/span><\/span>)\n <\/span>\n \n \n POL\n \n \n \n <\/span>\n <\/a>\n <\/span><\/a>\n \n <\/span>\n <\/a>\n \n <\/span>\n <\/span>\n \n <\/span>\n <\/td>\n <\/tr>\n
8<\/td>\n \n \n Colony\n <\/td>\n \n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n
\n \"\"\/\n <\/div>\n <\/td>\n
\n \n rosy<\/span>\n <\/a>\n \n (hp<\/span><\/span>)\n <\/span>\n \n <\/td>\n \n \n \n <\/span>\n <\/a>\n <\/span><\/a>\n \n <\/span>\n <\/a>\n \n <\/span>\n <\/span>\n \n <\/span>\n <\/td>\n <\/tr>\n
9<\/td>\n \n \n Colony\n <\/td>\n \n \n \n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n  <\/span>\n \n KalDiaC<\/span>\n <\/a>\n \n (hp<\/span><\/span>)\n <\/span>\n \n \n P-F\n \n \n \n <\/span>\n <\/a>\n <\/span><\/a>\n \n <\/span>\n <\/a>\n \n <\/span>\n <\/span>\n \n <\/span>\n <\/td>\n <\/tr>\n
10<\/td>\n \n \n Colony\n <\/td>\n \n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n
\n \"\"\/\n <\/div>\n <\/td>\n
\n \n rosy<\/span>\n <\/a>\n \n (hp<\/span><\/span>)\n <\/span>\n \n <\/td>\n \n \n \n <\/span>\n <\/a>\n <\/span><\/a>\n \n <\/span>\n <\/a>\n \n <\/span>\n <\/span>\n \n <\/span>\n <\/td>\n <\/tr>\n
11<\/td>\n \n \n Colony\n <\/td>\n \n \n \n \n  <\/span>\n \n KalDiaC<\/span>\n <\/a>\n \n (hp<\/span><\/span>)\n <\/span>\n \n \n P-F\n \n \n \n <\/span>\n <\/a>\n <\/span><\/a>\n \n <\/span>\n <\/a>\n \n <\/span>\n <\/span>\n \n <\/span>\n <\/td>\n <\/tr>\n
12<\/td>\n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n <\/span>\n <\/a>\n <\/td>\n \n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n
\n \"\"\/\n <\/div>\n <\/td>\n
\n \n <\/span>\n \n <\/span>\n <\/td>\n \n <\/td>\n \n \n <\/span>\n <\/td>\n <\/tr>\n
13<\/td>\n \n \n Colony\n <\/td>\n \n \n \n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n  <\/span>\n \n KalDiaC<\/span>\n <\/a>\n \n (hp<\/span><\/span>)\n <\/span>\n \n \n P-F\n \n \n \n <\/span>\n <\/a>\n <\/span><\/a>\n \n <\/span>\n <\/a>\n \n <\/span>\n <\/span>\n \n <\/span>\n <\/td>\n <\/tr>\n
14<\/td>\n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n <\/span>\n <\/a>\n <\/td>\n \n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n
\n \"\"\/\n <\/div>\n <\/td>\n
\n \n <\/span>\n \n <\/span>\n <\/td>\n \n <\/td>\n \n \n <\/span>\n <\/td>\n <\/tr>\n
15<\/td>\n \n \n Buying duet\n <\/td>\n \n \n \n \n
\n \"\"\/\n <\/div>\n <\/td>\n
\n  <\/span>\n \n Ray<\/span>\n <\/a>\n \n (v<\/span><\/span>)\n <\/span>\n \n <\/td>\n \n \n \n <\/span>\n <\/a>\n <\/span><\/a>\n \n <\/span>\n <\/a>\n \n <\/span>\n <\/span>\n \n <\/span>\n <\/td>\n <\/tr>\n \n <\/tbody>\n <\/table>\n\n \n \n
\n

Legend<\/h1>\n
<\/div>\n
\n
A<\/dt>\n
Administrator<\/dd>\n\n
s<\/dt>\n
Stronger Player<\/dd>\n\n
n<\/dt>\n
Weaker Player (newbie)<\/dd>\n\n
o<\/dt>\n
Outlaw (temporary)<\/dd>\n\n
v<\/dt>\n
Vacation Mode<\/dd>\n\n
b<\/dt>\n
Banned<\/dd>\n\n
i<\/dt>\n
7 days inactive<\/dd>\n\n
I<\/dt>\n
28 days inactive<\/dd>\n\n
hp<\/dt>\n
Honourable target<\/dd>\n <\/dl>\n <\/div>\n <\/div>\n