34 lines
828 B
Go
34 lines
828 B
Go
package cron
|
|
|
|
import (
|
|
"log"
|
|
|
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/domain"
|
|
"git.jamestombleson.com/jtom38/newsbot-api/internal/services/input"
|
|
)
|
|
|
|
// This is the main entry point to query all the reddit services
|
|
func (c *Cron) CheckReddit() {
|
|
sources, err := c.repo.Sources.ListBySource(*c.ctx, 0, 100, domain.SourceCollectorReddit)
|
|
if err != nil {
|
|
log.Printf("[Reddit] No sources found to query - %v\r", err)
|
|
}
|
|
|
|
for _, source := range sources {
|
|
if !source.Enabled {
|
|
continue
|
|
}
|
|
|
|
log.Printf("[Reddit] Checking '%v'...", source.DisplayName)
|
|
rc := input.NewRedditClient(source)
|
|
raw, err := rc.GetContent()
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
redditArticles := rc.ConvertToArticles(raw)
|
|
|
|
c.SaveNewArticles(redditArticles, domain.SourceCollectorReddit)
|
|
}
|
|
log.Print("[Reddit] Done!")
|
|
}
|