diff --git a/scraper/poll.go b/scraper/poll.go index e0f760b..2e1bd16 100644 --- a/scraper/poll.go +++ b/scraper/poll.go @@ -22,7 +22,7 @@ type Poll struct { VotingDuration int // In seconds VotingEndsAt time.Time - LastScrapedAt time.Time + LastUpdatedAt time.Time } func ParseAPIPoll(apiCard APICard) Poll { @@ -30,11 +30,16 @@ func ParseAPIPoll(apiCard APICard) Poll { if err != nil { panic(err) } + last_updated_at, err := time.Parse(time.RFC3339, apiCard.BindingValues.LastUpdatedAt.StringValue) + if err != nil { + panic(err) + } ret := Poll{} ret.NumChoices = parse_num_choices(apiCard.Name) ret.VotingDuration = int_or_panic(apiCard.BindingValues.DurationMinutes.StringValue) * 60 ret.VotingEndsAt = voting_ends_at + ret.LastUpdatedAt = last_updated_at ret.Choice1 = apiCard.BindingValues.Choice1.StringValue ret.Choice1_Votes = int_or_panic(apiCard.BindingValues.Choice1_Count.StringValue) diff --git a/scraper/poll_test.go b/scraper/poll_test.go index 188ab6e..97a88b8 100644 --- a/scraper/poll_test.go +++ b/scraper/poll_test.go @@ -30,6 +30,13 @@ func TestParsePoll2Choices(t *testing.T) { if poll.VotingEndsAt.Unix() != expected_ending { t.Errorf("Expected closing time %d, got %d", expected_ending, poll.VotingEndsAt.Unix()) } + expected_last_updated := int64(1636318755) + if poll.LastUpdatedAt.Unix() != expected_last_updated { + t.Errorf("Expected last-updated time %d, got %d", expected_last_updated, poll.LastUpdatedAt.Unix()) + } + if expected_last_updated > expected_ending { + t.Errorf("Last updated should be before poll closes!") + } if poll.Choice1 != "Yes" || poll.Choice2 != "No" { t.Errorf("Expected %q and %q, got %q and %q", "Yes", "No", poll.Choice1, poll.Choice2) @@ -64,6 +71,13 @@ func TestParsePoll4Choices(t *testing.T) { if poll.VotingEndsAt.Unix() != expected_ending { t.Errorf("Expected closing time %d, got %d", expected_ending, poll.VotingEndsAt.Unix()) } + expected_last_updated := int64(1635966226) + if poll.LastUpdatedAt.Unix() != expected_last_updated { + t.Errorf("Expected last-updated time %d, got %d", expected_last_updated, poll.LastUpdatedAt.Unix()) + } + if expected_last_updated < expected_ending { + t.Errorf("Last updated should be after poll closes!") + } if poll.Choice1 != "Alec Baldwin" || poll.Choice1_Votes != 1669 { t.Errorf("Expected %q with %d, got %q with %d", "Alec Baldwin", 1669, poll.Choice1, poll.Choice1_Votes)