Merge pull request #192 from velour/webshit_urls

webshit: fix URL matching to use query string
This commit is contained in:
Chris Sexton 2019-08-08 10:24:05 -04:00 committed by GitHub
commit 05bb70e3a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 5 deletions

1
.gitignore vendored
View File

@ -70,3 +70,4 @@ util/*/files
run.sh
.idea
logs
util/files

View File

@ -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

View File

@ -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)