hnbot/main.go

37 lines
645 B
Go
Raw Normal View History

package main
2023-04-25 09:51:12 +00:00
import (
"errors"
"log"
"time"
)
2023-04-19 22:20:46 +00:00
func main() {
2023-04-19 22:20:46 +00:00
for {
2023-04-25 09:51:12 +00:00
stories, err := FetchHackerNewsTopStories()
if err != nil {
SendErrorToDiscord(err)
time.Sleep(time.Hour)
continue
}
2023-04-19 22:20:46 +00:00
filtered := CurateContentForStackerNews(&stories)
2023-04-25 09:51:12 +00:00
2023-04-19 22:20:46 +00:00
for _, story := range *filtered {
2023-04-25 09:51:12 +00:00
_, err := PostStoryToStackerNews(&story, PostStoryOptions{SkipDupes: false})
if err != nil {
var dupesErr *DupesError
if errors.As(err, &dupesErr) {
SendDupesErrorToDiscord(story.ID, dupesErr)
continue
}
SendErrorToDiscord(err)
continue
}
log.Println("Posting to SN ... OK")
2023-04-19 22:20:46 +00:00
}
time.Sleep(time.Hour)
}
}