-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
65 lines (55 loc) · 1.31 KB
/
main.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"iulianpascalau/kaching-go/blockchain"
"iulianpascalau/kaching-go/logging"
"os"
"os/exec"
"os/signal"
"syscall"
"time"
)
const filename = "./kaching.mp3"
const address = "https://api.elrond.com"
const poolInterval = time.Second * 6 //round time
func main() {
defer logging.MainLogger.CloseLogFile()
if !fileExists(filename) {
logging.MainLogger.Log(fmt.Sprintf("file %s not found!", filename))
}
logging.MainLogger.Log("application started")
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
chPlaySound := make(chan struct{}, 1)
ew := blockchain.NewEpochWatcher(address, poolInterval, chPlaySound)
defer ew.Close()
for {
select {
case <-sigs:
logging.MainLogger.Log("terminating at user's signal...")
return
case <-chPlaySound:
playSound(filename)
}
}
}
// fileExists checks if a file exists and is not a directory before we
// try using it to prevent further errors.
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}
func playSound(filename string) {
logging.MainLogger.Log("playing kaching...")
app := "mpg123"
arg := filename
cmd := exec.Command(app, arg)
_, err := cmd.Output()
if err != nil {
fmt.Println(err.Error())
return
}
}