Skip to content

Commit

Permalink
event: Be more defensive on category and platform
Browse files Browse the repository at this point in the history
Both category and platform can be missing, or only one of the two be
set. Default both to unknown, and only when we get two non-empty matches
after splitting on the '—' do we fill them in.
  • Loading branch information
daenney committed Dec 10, 2020
1 parent 7078566 commit fba6b0a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,18 @@ func eventFromHTML(rows ...soup.Root) (*Event, error) {

e.Estimate = toDuration(tr2[0].Text())
catPlat := strings.Split(tr2[1].Text(), "—") // Ceci n'est pas un -
e.Category = strings.TrimSpace(catPlat[0])
e.Platform = strings.TrimSpace(catPlat[1])
category := "unknown"
platform := "unknown"
if len(catPlat) == 2 {
if c := strings.TrimSpace(catPlat[0]); c != "" {
category = c
}
if p := strings.TrimSpace(catPlat[1]); p != "" {
platform = p
}
}
e.Category = category
e.Platform = platform
e.Hosts = nicksToSlice(tr2[2].Text())

return e, nil
Expand Down

0 comments on commit fba6b0a

Please sign in to comment.