2023-04-28 15:34:26 +00:00
|
|
|
package main
|
|
|
|
|
2023-04-28 16:24:02 +00:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func WaitUntilNextUpdate() {
|
|
|
|
now := time.Now()
|
2023-05-15 10:16:47 +00:00
|
|
|
dur := now.Truncate(time.Minute).Add(time.Minute).Sub(now)
|
2023-04-28 16:24:02 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-04-28 15:34:26 +00:00
|
|
|
func main() {
|
2023-05-07 16:30:02 +00:00
|
|
|
defer db.Close()
|
2023-04-28 16:24:02 +00:00
|
|
|
for {
|
|
|
|
rss, err := FetchStackerNewsRssFeed()
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
WaitUntilNextUpdate()
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, item := range rss.Channel.Items {
|
2023-05-07 16:30:02 +00:00
|
|
|
if ItemExists(item) {
|
|
|
|
log.Printf("item %s already exists. skipping.\n", item.Guid)
|
2023-04-28 16:24:02 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
err := SendItemToTelegram(&item)
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
continue
|
|
|
|
}
|
2023-05-07 16:30:02 +00:00
|
|
|
SaveItem(item)
|
2023-04-28 16:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WaitUntilNextUpdate()
|
|
|
|
}
|
2023-04-28 15:34:26 +00:00
|
|
|
}
|