diff options
| author | Christine Dodrill <xena@yolo-swag.com> | 2015-08-20 22:55:35 -0700 |
|---|---|---|
| committer | Christine Dodrill <xena@yolo-swag.com> | 2015-08-20 22:55:35 -0700 |
| commit | 4685feb57754c89ab6d6cb18e89de124fa4f80fe (patch) | |
| tree | fec16c6eb9b2ceb1ce71ffe0fbb9cf6eda1fc956 | |
| parent | 32759080bcdd98454933658a2036619a96e7a073 (diff) | |
| download | x-4685feb57754c89ab6d6cb18e89de124fa4f80fe.tar.xz x-4685feb57754c89ab6d6cb18e89de124fa4f80fe.zip | |
Add splattus tool
| -rw-r--r-- | splattus/.gitignore | 1 | ||||
| -rw-r--r-- | splattus/lib/handler.go | 28 | ||||
| -rw-r--r-- | splattus/lib/maps.go | 31 | ||||
| -rw-r--r-- | splattus/lib/stage.go | 12 | ||||
| -rw-r--r-- | splattus/main.go | 38 |
5 files changed, 110 insertions, 0 deletions
diff --git a/splattus/.gitignore b/splattus/.gitignore new file mode 100644 index 0000000..00ab0db --- /dev/null +++ b/splattus/.gitignore @@ -0,0 +1 @@ +splattus diff --git a/splattus/lib/handler.go b/splattus/lib/handler.go new file mode 100644 index 0000000..328d060 --- /dev/null +++ b/splattus/lib/handler.go @@ -0,0 +1,28 @@ +package splattus + +import ( + "encoding/json" + "io/ioutil" + "net/http" +) + +func Lookup() ([]SplatoonData, error) { + resp, err := http.Get(url) + if err != nil { + return nil, err + } + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + var sd []SplatoonData + err = json.Unmarshal(body, &sd) + if err != nil { + return nil, err + } + + return sd, nil +} diff --git a/splattus/lib/maps.go b/splattus/lib/maps.go new file mode 100644 index 0000000..29aa883 --- /dev/null +++ b/splattus/lib/maps.go @@ -0,0 +1,31 @@ +package splattus + +import "fmt" + +const url = "https://s3-ap-northeast-1.amazonaws.com/splatoon-data.nintendo.net/stages_info.json" + +var mapNames map[string]string + +func init() { + mapNames = map[string]string{ + "eefffc33ee1956b7b70e250d5835aa67be9152d42bc76aa8874987ebdfc19944": "Urchin Underpass", + "b8067d2839476ec39072e371b4c59fa85454cdb618515af080ca6080772f3264": "Port Mackerel", + "50c01bca5b3117f4f7893df86d2e2d95435dbb1aae1da6831b8e74838859bc7d": "Saltspray Rig", + "9a1736540c3fde7e409cb9c7e333441157d88dfe8ce92bc6aafcb9f79c56cb3d": "Blackbelly Skatepark", + "d7bf0ca4466e980f994ef7b32faeb71d80611a28c5b9feef84a00e3c4c9d7bc1": "Walleye Warehouse", + "8c69b7c9a81369b5cfd22adbf41c13a8df01969ff3d0e531a8bcb042156bc549": "Arowana Mall", + "1ac0981d03c18576d9517f40461b66a472168a8f14f6a8714142af9805df7b8c": "Bluefin Depot", + "c52a7ab7202a576ee18d94be687d97190e90fdcc25fc4b1591c1a8e0c1c299a5": "Kelp Dome", + "6a6c3a958712adedcceb34f719e220ab0d840d8753e5f51b089d363bd1763c91": "Moray Towers", + "a54716422edf71ac0b3d20fbb4ba5970a7a78ba304fcf935aaf69254d61ca709": "Flounder Heights", + } +} + +func Englishify(s *Stage) string { + name, ok := mapNames[s.ID] + if !ok { + return fmt.Sprintf("Please tell Xena the name of stage id \"%s\" with jpn name %s", s.ID, s.Name) + } + + return name +} diff --git a/splattus/lib/stage.go b/splattus/lib/stage.go new file mode 100644 index 0000000..e9d59a5 --- /dev/null +++ b/splattus/lib/stage.go @@ -0,0 +1,12 @@ +package splattus + +type SplatoonData struct { + DatetimeTermBegin string `json:"datetime_term_begin"` + DatetimeTermEnd string `json:"datetime_term_end"` + Stages []*Stage `json:"stages"` +} + +type Stage struct { + ID string `json:"id"` + Name string `json:"name"` +} diff --git a/splattus/main.go b/splattus/main.go new file mode 100644 index 0000000..da0a351 --- /dev/null +++ b/splattus/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "flag" + "fmt" + "log" + + "github.com/Xe/tools/splattus/lib" + "github.com/mgutz/ansi" +) + +var ( + firstColor = flag.String("firstColor", "208", "first color to use") + secondColor = flag.String("secondColor", "21", "second color to use") + prefixMsg = flag.String("prefix", "Current Splatoon rotation: ", "prefix messsage with this") +) + +func init() { + flag.Parse() +} + +func main() { + sd, err := splattus.Lookup() + if err != nil { + log.Fatal(err) + } + + data := sd[0] + stage1 := data.Stages[0] + stage2 := data.Stages[1] + + fmt.Printf( + "%s%s and %s\n", + *prefixMsg, + ansi.Color(splattus.Englishify(stage1), *firstColor), + ansi.Color(splattus.Englishify(stage2), *secondColor), + ) +} |
