-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (57 loc) · 1.17 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
66
package main
import (
"fmt"
"github.com/dzfranklin/minusnet/hubs"
"github.com/dzfranklin/minusnet/stores"
_ "github.com/mattn/go-sqlite3"
"go.uber.org/zap"
"os"
)
var hub *hubs.Hub
var store *stores.Store
func main() {
logger, err := zap.NewDevelopment()
if err != nil {
panic(err)
}
zap.ReplaceGlobals(logger)
l := zap.S()
hub = &hubs.Hub{
Addr: "192.168.1.254",
Serial: "+108417+2216005167",
}
dataDir := os.Getenv("MINUSNET_DATA_DIR")
if dataDir == "" {
dataDir = "/tmp/minusnet"
}
store, err = stores.New(dataDir)
defer func() {
if err := store.Close(); err != nil {
l.Errorf("failed to close store: %s", err)
}
}()
if len(os.Args) < 2 {
println("usage: minusnet <command>")
os.Exit(1)
}
switch os.Args[1] {
case "scrape":
scrapeMain()
default:
fmt.Printf("unknown command: %s", os.Args[1])
os.Exit(1)
}
}
func scrapeMain() {
l := zap.S()
l.Info("scraping")
status, err := hub.RequestStatus()
if err != nil {
l.Fatalf("failed to request status: %s", err)
}
l.Infof("got status:\n%s", status)
if err := store.RecordStatus(status); err != nil {
l.Fatalf("failed to insert status: %s", err)
}
l.Info("stored status")
}