42 lines
841 B
Go
42 lines
841 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
Setup()
|
|
SetupActors()
|
|
go func() {
|
|
ticker := time.NewTicker(60 * time.Second)
|
|
defer ticker.Stop()
|
|
for {
|
|
select {
|
|
case t := <-ticker.C:
|
|
fmt.Println("Fetch feeds: ", t.Format(time.RFC3339))
|
|
for _, actor := range actors {
|
|
fmt.Println(actor.feed)
|
|
articles, err := allFeedItems(actor.feed)
|
|
if err != nil {
|
|
fmt.Println(actor.feed, err.Error())
|
|
continue
|
|
}
|
|
// Prevent map from getting to big
|
|
oldSentItems := actor.sentItems
|
|
actor.sentItems = make(map[string]bool)
|
|
for _, article := range articles {
|
|
if oldSentItems[article] == false {
|
|
fmt.Println("Send", article)
|
|
go actor.PostArticle(article)
|
|
}
|
|
actor.sentItems[article] = true
|
|
}
|
|
_ = actor.save()
|
|
}
|
|
}
|
|
}
|
|
}()
|
|
Serve()
|
|
}
|