From 9fde6e5a892b228c2d64af05b02380847573c832 Mon Sep 17 00:00:00 2001 From: Andinus Date: Sun, 22 Mar 2020 13:43:54 +0530 Subject: Add initial version --- cmd/indus/main.go | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'cmd/indus/main.go') diff --git a/cmd/indus/main.go b/cmd/indus/main.go index 38dd16d..ce3aa91 100644 --- a/cmd/indus/main.go +++ b/cmd/indus/main.go @@ -1,3 +1,48 @@ package main -func main() {} +import ( + "fmt" + "log" + + "framagit.org/andinus/indus/clipboard" + "framagit.org/andinus/indus/fetch" + "framagit.org/andinus/indus/summarize" +) + +func main() { + // Get the primary clipboard selection. + sel, err := clipboard.GetSel() + if err != nil { + log.Fatal(err) + } + + // If the selection is an empty string then the program should + // exit because otherwise Notify function will fail with + // non-zero exit code. + if len(sel) == 0 { + err = fmt.Errorf("clipboard: primary clipboard empty") + log.Fatal(err) + } + + notifyWiki(sel) +} + +func notifyWiki(sel string) { + // Fetch the summary from wikipedia. + w, err := fetch.Wikipedia(sel) + if err != nil { + log.Fatal(err) + } + + // Get notification information. + n, err := summarize.Wikipedia(w) + if err != nil { + log.Fatal(err) + } + + // Send a desktop notification to the user. + err = n.Notify() + if err != nil { + log.Fatal(err) + } +} -- cgit 1.4.1-2-gfad0