-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss-pushover.go
37 lines (34 loc) · 1005 Bytes
/
rss-pushover.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"github.com/mmcdole/gofeed"
"time"
"net/http"
"net/url"
"os"
"strconv"
"fmt"
)
func main () {
refresh_int, _ := strconv.Atoi(os.Getenv("REFRESH_INTERVAL"))
delta_int, _ := strconv.Atoi(os.Getenv("CHECK_DELTA"))
refresh_time := time.Duration(refresh_int)
delta_time := time.Duration(delta_int)
for {
checktime := time.Now().Add(time.Minute * -(refresh_time + delta_time))
fp := gofeed.NewParser()
feed, _ := fp.ParseURL(os.Getenv("FEED_URL"))
timeT, _ := time.Parse("Mon, 02 Jan 2006 15:04:05 MST", feed.Updated)
fmt.Println(feed.Items[0].Title,"at",timeT)
if checktime.Before(timeT) {
fmt.Println("New item found, sending push notification...")
data := url.Values{
"token": {os.Getenv("PUSHOVER_TOKEN")},
"user": {os.Getenv("PUSHOVER_USER")},
"message": {feed.Items[0].Title},
"url": {feed.Items[0].Link},
}
_, _ = http.PostForm("https://api.pushover.net/1/messages.json", data)
}
time.Sleep(refresh_time * time.Minute)
}
}