commit 1182feed25d1334b7bb33f80ff8ac74fddeb2630 Author: yakumo.izuru Date: Mon May 29 20:58:24 2023 +0000 Initial payload Signed-off-by: Izuru Yakumo git-svn-id: https://svn.yakumo.dev/yakumo.izuru/yuuka/trunk@1 10373541-e681-4840-9083-43024fea98c9 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1848005 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +yuuka diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..2cf0779 --- /dev/null +++ b/COPYING @@ -0,0 +1,13 @@ +Copyright (c) 2023-present Izuru Yakumo + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..081dd37 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# yuuka +It's a [wttr](https://wttr.in) client, named after [Yuuka Kazami](https://en.touhouwiki.net/wiki/Yuuka_Kazami) from [Touhou 4: Lotus Land Story](https://en.touhouwiki.net/wiki/Lotus_Land_Story) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..bbaea4f --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module marisa.chaotic.ninja/yuuka + +go 1.20 diff --git a/main.go b/main.go new file mode 100644 index 0000000..5c5fc98 --- /dev/null +++ b/main.go @@ -0,0 +1,57 @@ +// $TheSupernovaDuo: yuuka,v master 2023/5/29 17:54:15 yakumo_izuru Exp $ +package main + +import ( + "fmt" + "io" + "log" + "net/http" + "os" +) +var ( + format = "?AT" + url = "https://wttr.in" +) +func main() { + if len(os.Args) == 1 { + PrintUsage() + } + + cmd := os.Args[1] + + switch cmd { + case "forecast": + ShowForecast() + case "moon": + ShowMoonPhases() + } +} +func PrintUsage() { + fmt.Println("Yuuka is a wttr.in client") + fmt.Printf("\tforecast\tShow the current weather report according to your region\n") + fmt.Printf("\tmoon\tShow the current phase of the Moon\n") +} + +func ShowForecast() { + query := url + format + resp, err := http.Get(query) + sanityCheck(err) + defer resp.Body.Close() + body, err := io.ReadAll(resp.Body) + sanityCheck(err) + fmt.Printf("%s", body) +} +func ShowMoonPhases() { + query := url + "/Moon" + format + resp, err := http.Get(query) + sanityCheck(err) + defer resp.Body.Close() + body, err := io.ReadAll(resp.Body) + sanityCheck(err) + fmt.Printf("%s\n", body) +} +func sanityCheck(err error) { + if err != nil { + log.Fatal(err) + } +}