From 705aa294d54e8d720ed2a82e98e0c2bc1f122125 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Thu, 8 Aug 2019 10:13:24 -0400 Subject: [PATCH 1/2] webshit: fix URL matching to use query string --- .gitignore | 1 + plugins/newsbid/webshit/webshit.go | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index fcf0e95..dffcaf7 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,4 @@ util/*/files run.sh .idea logs +util/files diff --git a/plugins/newsbid/webshit/webshit.go b/plugins/newsbid/webshit/webshit.go index dead1ae..4571952 100644 --- a/plugins/newsbid/webshit/webshit.go +++ b/plugins/newsbid/webshit/webshit.go @@ -123,7 +123,13 @@ func (w *Webshit) Check() ([]WeeklyResult, error) { storyMap := map[string]Story{} for _, s := range stories { - storyMap[s.URL] = s + u, err := url.Parse(s.URL) + if err != nil { + log.Error().Err(err).Msg("couldn't parse URL") + continue + } + id := u.Query().Get("id") + storyMap[id] = s } wr := w.checkBids(bids, storyMap) @@ -162,7 +168,14 @@ func (w *Webshit) checkBids(bids []Bid, storyMap map[string]Story) []WeeklyResul } rec := wr[b.User] - if s, ok := storyMap[b.URL]; ok { + u, err := url.Parse(b.URL) + if err != nil { + log.Error().Err(err).Msg("couldn't parse URL") + continue + } + id := u.Query().Get("id") + + if s, ok := storyMap[id]; ok { log.Debug().Interface("story", s).Msg("won bid") rec.Won += b.Bid rec.Score += b.Bid From 4ef471eff245daf25b362f39e2bb4690bc9e686b Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Thu, 8 Aug 2019 10:19:52 -0400 Subject: [PATCH 2/2] webshit: add missing test update --- plugins/newsbid/webshit/webshit_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/newsbid/webshit/webshit_test.go b/plugins/newsbid/webshit/webshit_test.go index 16a9e18..0f2cf17 100644 --- a/plugins/newsbid/webshit/webshit_test.go +++ b/plugins/newsbid/webshit/webshit_test.go @@ -62,11 +62,11 @@ func TestWebshit_GetBalance(t *testing.T) { func TestWebshit_checkBids(t *testing.T) { w := makeWS(t) bids := []Bid{ - Bid{User: "foo", Title: "bar", URL: "baz", Bid: 10}, - Bid{User: "foo", Title: "bar2", URL: "baz2", Bid: 10}, + Bid{User: "foo", Title: "bar", URL: "https://baz/?id=1", Bid: 10}, + Bid{User: "foo", Title: "bar2", URL: "http://baz/?id=2", Bid: 10}, } storyMap := map[string]Story{ - "baz": Story{Title: "bar", URL: "baz"}, + "1": Story{Title: "bar", URL: "http://baz/?id=1"}, } result := w.checkBids(bids, storyMap) assert.Len(t, result, 1)