53 lines
852 B
Go
53 lines
852 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"time"
|
|
)
|
|
|
|
func WaitUntilNextUpdate() {
|
|
now := time.Now()
|
|
dur := now.Truncate(time.Hour).Add(time.Hour).Sub(now)
|
|
log.Println("sleeping for", dur.Round(time.Second))
|
|
time.Sleep(dur)
|
|
}
|
|
|
|
func contains(rss *Rss, a Item) bool {
|
|
if rss == nil {
|
|
return false
|
|
}
|
|
for _, x := range rss.Channel.Items {
|
|
if x.Title == a.Title {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func main() {
|
|
defer db.Close()
|
|
for {
|
|
rss, err := FetchStackerNewsRssFeed()
|
|
if err != nil {
|
|
log.Println(err)
|
|
WaitUntilNextUpdate()
|
|
continue
|
|
}
|
|
|
|
for _, item := range rss.Channel.Items {
|
|
if ItemExists(item) {
|
|
log.Printf("item %s already exists. skipping.\n", item.Guid)
|
|
continue
|
|
}
|
|
err := SendItemToTelegram(&item)
|
|
if err != nil {
|
|
log.Println(err)
|
|
continue
|
|
}
|
|
SaveItem(item)
|
|
}
|
|
|
|
WaitUntilNextUpdate()
|
|
}
|
|
}
|