Initial payload
Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja> git-svn-id: file:///srv/svn/repo/yuuka/trunk@1 10373541-e681-4840-9083-43024fea98c9
This commit is contained in:
commit
e9bb0f129d
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
yuuka
|
13
COPYING
Normal file
13
COPYING
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
Copyright (c) 2023-present Izuru Yakumo <yakumo.izuru@chaotic.ninja>
|
||||||
|
|
||||||
|
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.
|
2
README.md
Normal file
2
README.md
Normal file
@ -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)
|
57
main.go
Normal file
57
main.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user