poesty 9 hónapja
szülő
commit
4816be78ca
1 módosított fájl, 6 hozzáadás és 3 törlés
  1. 6 3
      rss2hook.go

+ 6 - 3
rss2hook.go

@@ -97,7 +97,7 @@ func checkFeeds(feeds []rss.Feed) {
 		}
 
 		if feed.Unread != 0 {
-			notify(i, feed.Items[0])
+			notify(i, feed.Items[len(feed.Items)-1])
 			feed.Unread = 0
 		}
 	}
@@ -111,8 +111,9 @@ func notify(i int, item *rss.Item) {
 		cmd := exec.Command(Loaded[i].Hook)
 		err := cmd.Start()
 		if err != nil {
-			log.Fatalf("notify: Failed to start command: %s\n", err.Error())
+			log.Fatalf("notify: Failed to start command: %s\n", err.Error()) // TODO: retry?
 		}
+		// TODO: write outputs to files, and graceful shutdown
 	} else if Loaded[i].Method == "webhook" {
 		// We'll post the item as a JSON object.
 		// So first of all encode it.
@@ -130,7 +131,7 @@ func notify(i int, item *rss.Item) {
 
 		if err != nil {
 			log.Printf("notify: Failed to POST to %s - %s\n",
-				Loaded[i].Hook, err.Error())
+				Loaded[i].Hook, err.Error()) // TODO: retry?
 			return
 		}
 
@@ -165,6 +166,7 @@ func main() {
 	flag.Parse()
 
 	// Setup the default timeout and TTL
+	// Remember that we respect spec, like `ttl` field in RSS 2.0
 	rss.DefaultRefreshInterval = 10 * time.Second
 	rss.DefaultFetchFunc = func(url string) (*http.Response, error) {
 		client := &http.Client{Timeout: *timeout}
@@ -197,6 +199,7 @@ func main() {
 					ent.Url, err.Error())
 				return
 			}
+			// TODO: validiy checks (webhook/command)
 			// feed.Unread = 0
 			feeds[i] = *feed
 		}(i, ent)