-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathannouncements.go
41 lines (35 loc) · 1.12 KB
/
announcements.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"github.com/underlx/disturbancesmlx/types"
"github.com/underlx/disturbancesmlx/scraper"
)
var annStore AnnouncementStore
// AnnouncementStore implements types.AnnouncementStore
type AnnouncementStore struct {
scrapers map[string]scraper.AnnouncementScraper
}
// AddScraper registers all sources provided by this scraper
func (as *AnnouncementStore) AddScraper(s scraper.AnnouncementScraper) {
if as.scrapers == nil {
as.scrapers = make(map[string]scraper.AnnouncementScraper)
}
for _, source := range s.Sources() {
as.scrapers[source] = s
}
}
// AllAnnouncements gets all announcements from all sources, unsorted
func (as *AnnouncementStore) AllAnnouncements() []*types.Announcement {
ann := []*types.Announcement{}
for source, scraper := range as.scrapers {
ann = append(ann, scraper.Announcements(source)...)
}
return ann
}
// SourceAnnouncements gets all announcements from a specific source
func (as *AnnouncementStore) SourceAnnouncements(source string) []*types.Announcement {
ann, ok := as.scrapers[source]
if !ok {
return []*types.Announcement{}
}
return ann.Announcements(source)
}