summary refs log tree commit diff stats
path: root/cmd/indus/main.go
blob: ce3aa917aefcb09edfd2d793a5614b56f6ce4627 (plain) (blame)
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
38
39
40
41
42
43
44
45
46
47
48
package 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)
	}
}