-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
62 lines (55 loc) · 1.08 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
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"os"
"sort"
"strings"
"github.com/rjeczalik/kkm"
)
var (
card = flag.String("card", "UJ", "Student card owner - two letter university name. By default UJ.")
id = flag.Int("id", 0, "Student card ID. Required.")
)
var avail []string
func die(v interface{}) {
fmt.Fprintln(os.Stderr, v)
os.Exit(1)
}
func init() {
avail = make([]string, 0, len(kkm.CityCardType))
for k := range kkm.CityCardType {
avail = append(avail, strings.ToUpper(k))
}
sort.Strings(avail)
}
func main() {
flag.CommandLine.Usage = func() {
flag.PrintDefaults()
fmt.Printf("\n Available university acronyms: %v\n", strings.Join(avail, ", "))
os.Exit(0)
}
if len(os.Args) == 1 {
flag.CommandLine.Usage()
}
flag.Parse()
if *id <= 0 {
die("invalid student card ID")
}
tickets, err := kkm.History(*card, *id)
if err != nil {
die(err)
}
p, err := json.Marshal(tickets)
if err != nil {
die(err)
}
var buf bytes.Buffer
if err = json.Indent(&buf, p, "", "\t"); err != nil {
die(err)
}
buf.WriteTo(os.Stdout)
fmt.Println()
}