summary refs log tree commit diff stats
path: root/cmd
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-03-23 13:32:16 +0530
committerAndinus <andinus@nand.sh>2020-03-23 13:32:16 +0530
commita6b03fa4bb89a8f0c3546f720d5b35178c29f499 (patch)
treea0092511e85360e9a11578e530ccd751cee124ec /cmd
parent929e30adced38ac82f4482aa8c0c813e6fa2471b (diff)
downloadcetus-a6b03fa4bb89a8f0c3546f720d5b35178c29f499.tar.gz
Add notify functionality to cetus
Diffstat (limited to 'cmd')
-rw-r--r--cmd/cetus/apod.go13
-rw-r--r--cmd/cetus/bpod.go13
-rw-r--r--cmd/cetus/main.go9
3 files changed, 33 insertions, 2 deletions
diff --git a/cmd/cetus/apod.go b/cmd/cetus/apod.go
index b99d899..cb5abae 100644
--- a/cmd/cetus/apod.go
+++ b/cmd/cetus/apod.go
@@ -7,6 +7,7 @@ import (
 
 	"framagit.org/andinus/cetus/pkg/apod"
 	"framagit.org/andinus/cetus/pkg/background"
+	"framagit.org/andinus/indus/notification"
 )
 
 func execAPOD() {
@@ -77,6 +78,18 @@ func execAPOD() {
 		apod.Print(res)
 	}
 
+	// Send a desktop notification if notify flag was passed
+	if *apodNotify {
+		n := notification.Notif{}
+		n.Title = res.Title
+		n.Message = fmt.Sprintf("%s\n\n%s",
+			res.Date,
+			res.Explanation)
+
+		err = n.Notify()
+		chkErr(err)
+	}
+
 	// Proceed only if the command was set because if it was fetch
 	// then it's already finished & should exit now.
 	if os.Args[1] == "fetch" {
diff --git a/cmd/cetus/bpod.go b/cmd/cetus/bpod.go
index f308d47..cf0a4bb 100644
--- a/cmd/cetus/bpod.go
+++ b/cmd/cetus/bpod.go
@@ -8,6 +8,7 @@ import (
 
 	"framagit.org/andinus/cetus/pkg/background"
 	"framagit.org/andinus/cetus/pkg/bpod"
+	"framagit.org/andinus/indus/notification"
 )
 
 func execBPOD() {
@@ -107,6 +108,18 @@ func execBPOD() {
 		bpod.Print(res)
 	}
 
+	// Send a desktop notification if notify flag was passed
+	if *bpodNotify {
+		n := notification.Notif{}
+		n.Title = res.Title
+		n.Message = fmt.Sprintf("%s\n\n%s",
+			res.StartDate,
+			res.Copyright)
+
+		err = n.Notify()
+		chkErr(err)
+	}
+
 	// Proceed only if the command was set because if it was fetch
 	// then it's already finished & should exit now.
 	if os.Args[1] == "fetch" {
diff --git a/cmd/cetus/main.go b/cmd/cetus/main.go
index b039f7a..0ff6b44 100644
--- a/cmd/cetus/main.go
+++ b/cmd/cetus/main.go
@@ -22,6 +22,9 @@ var (
 	bpodPathOnly *bool
 	bpodQuiet    *bool
 	bpodDump     *bool
+
+	apodNotify *bool
+	bpodNotify *bool
 )
 
 func main() {
@@ -52,6 +55,8 @@ func main() {
 	rand.Seed(time.Now().Unix())
 
 	apodCmd := flag.NewFlagSet("apod", flag.ExitOnError)
+	bpodCmd := flag.NewFlagSet("bpod", flag.ExitOnError)
+
 	defDate := time.Now().UTC().Format("2006-01-02")
 
 	// Flags to parse for apod service.
@@ -62,8 +67,7 @@ func main() {
 	apodPathOnly = apodCmd.Bool("path-only", false, "Print only the path")
 	apodQuiet = apodCmd.Bool("quiet", false, "Stay quiet")
 	apodDump = apodCmd.Bool("dump", false, "Dump received response")
-
-	bpodCmd := flag.NewFlagSet("bpod", flag.ExitOnError)
+	apodNotify = apodCmd.Bool("notify", false, "Send a desktop notification with background information")
 
 	// Flags to parse for bpod service.
 	bpodAPI = bpodCmd.String("api", "https://www.bing.com/HPImageArchive.aspx", "BPOD API")
@@ -71,6 +75,7 @@ func main() {
 	bpodPathOnly = bpodCmd.Bool("path-only", false, "Print only the path")
 	bpodQuiet = bpodCmd.Bool("quiet", false, "Stay quiet")
 	bpodDump = bpodCmd.Bool("dump", false, "Dump received response")
+	bpodNotify = bpodCmd.Bool("notify", false, "Send a desktop notification with background information")
 
 	// Switching on commands will cause more repetition than
 	// switching on service. If we switch on commands then switch