tss/app/app.go
2022-04-28 19:24:21 -04:00

72 lines
1.5 KiB
Go

package app
import "go.balki.me/tss/log"
func Run(configPath string) {
cfg, err := ParseConfig(configPath)
if err != nil {
log.Panic("failed to parse config", "path", configPath, "err", err)
}
scheduler, err := NewScheduler(cfg.LastSuccessPath)
defer func() {
if err := scheduler.Save(); err != nil {
log.Panic("failed to save last success info", "path", cfg.LastSuccessPath, "err", err)
}
}()
for _, feed := range cfg.Feeds {
log.Info("processing feed", "feed", feed.Name)
ProcessFeed(feed, scheduler)
}
/*
for _, feed := range cfg.Feeds {
log.Println("Processing feed", feed.Name)
data, err := Download(feed.Url, feed.Proxy)
if err != nil {
log.Fatal(err)
}
}
for _, feed := range c.Feeds {
log.Println("Processing feed", feed.Name)
links, err := parseFeed(data)
if err != nil {
log.Fatal(err)
}
for _, link := range links {
if alreadySent(link) {
continue
}
err := sendTelegram(link, feed.Channel, feed.Rhash)
if err != nil {
log.Fatal(err)
}
}
}
fmt.Println(configPath)
*/
}
func ProcessFeed(feed FeedCfg, scheduler *Scheduler) {
sd, err := scheduler.ShouldDownload(feed.Name, feed.Cron)
if err != nil {
log.Error("shouldDownload failed", "feed", feed.Name, "err", err)
return
}
if !sd {
log.Info("skipping feed due to schedule", "feed", feed.Name)
return
}
_, err = Download(feed.Url, feed.Proxy)
if err != nil {
log.Error("download failed", "feed", feed.Name, "url", feed.Url, "proxy", feed.Proxy)
return
}
}