-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmain.go
86 lines (66 loc) · 1.69 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"fmt"
"log"
"os"
"path"
"time"
"github.com/jason0x43/go-alfred"
)
var cacheFile string
var configFile string
var workflow alfred.Workflow
type configStruct struct {
Service string `desc:"Service to use"`
OpenWeatherKey string `desc:"Your API key for OpenWeather"`
TomorrowIoKey string `desc:"Your API key for Tomorrow.io"`
Icons string `desc:"Icon set"`
DateFormat string `desc:"Date format"`
TimeFormat string `desc:"Time format"`
Location Location `desc:"Default location"`
Units units `desc:"Units"`
}
var config configStruct
var cache struct {
Weather Weather
Time time.Time
Service string
}
var dlog = log.New(os.Stderr, "[weather] ", log.LstdFlags)
func main() {
var err error
if workflow, err = alfred.OpenWorkflow(".", true); err != nil {
fmt.Printf("Error: %s", err)
os.Exit(1)
}
workflow.UpdateIcon = "notice.png"
configFile = path.Join(workflow.DataDir(), "config.json")
cacheFile = path.Join(workflow.CacheDir(), "cache.json")
dlog.Println("Using config file", configFile)
dlog.Println("Using cache file", cacheFile)
if err := alfred.LoadJSON(configFile, &config); err == nil {
dlog.Println("loaded config")
}
if err := alfred.LoadJSON(cacheFile, &cache); err == nil {
dlog.Println("loaded cache")
}
if config.TimeFormat == "" {
config.TimeFormat = TimeFormats[0]
}
if config.DateFormat == "" {
config.DateFormat = DateFormats[0]
}
if config.Icons == "" {
config.Icons = "grzanka"
}
if config.Units == "" {
config.Units = unitsUS
}
commands := []alfred.Command{
DailyCommand{},
HourlyCommand{},
OptionsCommand{},
RefreshCommand{},
}
workflow.Run(commands)
}