Browse Source

add option to support NOT skipping the first scan

boyska 4 years ago
parent
commit
1159f53933
2 changed files with 10 additions and 8 deletions
  1. 5 4
      app/cmd/rss2cmd/main.go
  2. 5 4
      app/rss/notify.go

+ 5 - 4
app/cmd/rss2cmd/main.go

@@ -21,9 +21,10 @@ import (
 )
 
 type opts struct {
-	Refresh time.Duration `short:"r" long:"refresh" env:"REFRESH" default:"30s" description:"refresh interval"`
-	TimeOut time.Duration `short:"t" long:"timeout" env:"TIMEOUT" default:"5s" description:"rss feed timeout"`
-	Feed    string        `short:"f" long:"feed" env:"FEED" required:"true" description:"rss feed url"`
+	Refresh      time.Duration `short:"r" long:"refresh" env:"REFRESH" default:"30s" description:"refresh interval"`
+	TimeOut      time.Duration `short:"t" long:"timeout" env:"TIMEOUT" default:"5s" description:"rss feed timeout"`
+	Feed         string        `short:"f" long:"feed" env:"FEED" required:"true" description:"rss feed url"`
+	IncludeFirst bool          `long:"include-first" description:"start from the last current item, not with the next one"`
 
 	Dry     bool `long:"dry" env:"DRY" description:"dry mode"`
 	Dbg     bool `long:"dbg" env:"DEBUG" description:"debug mode"`
@@ -140,7 +141,7 @@ func main() {
 }
 
 func setup(o opts) (n notifier, pub Publisher, err error) {
-	n = &rss.Notify{Feed: o.Feed, Duration: o.Refresh, Timeout: o.TimeOut}
+	n = &rss.Notify{Feed: o.Feed, Duration: o.Refresh, Timeout: o.TimeOut, IncludeFirst: o.IncludeFirst}
 	if o.Dry {
 		pub = Stdout{}
 	} else {

+ 5 - 4
app/rss/notify.go

@@ -13,9 +13,10 @@ import (
 
 // Notify on RSS change
 type Notify struct {
-	Feed     string
-	Duration time.Duration
-	Timeout  time.Duration
+	Feed         string
+	Duration     time.Duration
+	Timeout      time.Duration
+	IncludeFirst bool
 
 	once   sync.Once
 	ctx    context.Context
@@ -72,7 +73,7 @@ func (n *Notify) Go(ctx context.Context) <-chan Event {
 			}
 			event, err := n.feedEvent(feedData)
 			if lastGUID != event.GUID && err == nil {
-				if lastGUID != "" { // don't notify on initial change
+				if n.IncludeFirst || lastGUID != "" { // don't notify on initial change
 					log.Printf("[INFO] new event %s - %s", event.GUID, event.Title)
 					ch <- event
 				} else {