54 lines
1.0 KiB
Go
54 lines
1.0 KiB
Go
|
package modules
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"time"
|
||
|
|
||
|
"git.dnix.de/an/xlog"
|
||
|
"github.com/mmcdole/gofeed"
|
||
|
)
|
||
|
|
||
|
var feedsFeeds = flag.String("feeds_feeds", "feeds.txt", "Feed list file")
|
||
|
var feedsChannel = flag.String("feeds_channel", "", "Target channel")
|
||
|
|
||
|
func init() {
|
||
|
MsgFuncs["feeds"] = feedsHandleMessage
|
||
|
RunFuncs["feeds"] = feedsRun
|
||
|
}
|
||
|
|
||
|
func feedsRun() {
|
||
|
time.Sleep(1 * time.Minute)
|
||
|
file, err := os.Open(feedsFeeds)
|
||
|
if err != nil {
|
||
|
xlog.Fatal(err.Error())
|
||
|
}
|
||
|
defer file.Close()
|
||
|
scanner := bufio.NewScanner(file)
|
||
|
for scanner.Scan() {
|
||
|
go feedsPoll(scanner.Text())
|
||
|
}
|
||
|
if err := scanner.Err(); err != nil {
|
||
|
xlog.Fatal(err.Error())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func feedsHandleMessage(m *Message) {
|
||
|
}
|
||
|
|
||
|
func feedsPoll(url string) {
|
||
|
last := time.Now()
|
||
|
for {
|
||
|
fp := gofeed.NewParser()
|
||
|
feed, _ := fp.ParseURL(url)
|
||
|
for _, item := range feed.Items {
|
||
|
if item.UpdatedParsed.Unix() > last.Unix() {
|
||
|
SayCh <- fmt.Sprintf("%s\n[FEEDS] %s : %s - %s\n", *feedsChannel, feed.Title, item.Title, item.Link)
|
||
|
}
|
||
|
}
|
||
|
last = time.Now()
|
||
|
time.Sleep(15 * time.Minute)
|
||
|
}
|
||
|
}
|