Last change
on this file since 1 was 1, checked in by Izuru Yakumo, 2 years ago |
Initial payload
Signed-off-by: Izuru Yakumo <yakumo.izuru@…>
|
File size:
1.0 KB
|
Line | |
---|
1 | // $TheSupernovaDuo: yuuka,v master 2023/5/29 17:54:15 yakumo_izuru Exp $
|
---|
2 | package main
|
---|
3 |
|
---|
4 | import (
|
---|
5 | "fmt"
|
---|
6 | "io"
|
---|
7 | "log"
|
---|
8 | "net/http"
|
---|
9 | "os"
|
---|
10 | )
|
---|
11 | var (
|
---|
12 | format = "?AT"
|
---|
13 | url = "https://wttr.in"
|
---|
14 | )
|
---|
15 | func main() {
|
---|
16 | if len(os.Args) == 1 {
|
---|
17 | PrintUsage()
|
---|
18 | }
|
---|
19 |
|
---|
20 | cmd := os.Args[1]
|
---|
21 |
|
---|
22 | switch cmd {
|
---|
23 | case "forecast":
|
---|
24 | ShowForecast()
|
---|
25 | case "moon":
|
---|
26 | ShowMoonPhases()
|
---|
27 | }
|
---|
28 | }
|
---|
29 | func PrintUsage() {
|
---|
30 | fmt.Println("Yuuka is a wttr.in client")
|
---|
31 | fmt.Printf("\tforecast\tShow the current weather report according to your region\n")
|
---|
32 | fmt.Printf("\tmoon\tShow the current phase of the Moon\n")
|
---|
33 | }
|
---|
34 |
|
---|
35 | func ShowForecast() {
|
---|
36 | query := url + format
|
---|
37 | resp, err := http.Get(query)
|
---|
38 | sanityCheck(err)
|
---|
39 | defer resp.Body.Close()
|
---|
40 | body, err := io.ReadAll(resp.Body)
|
---|
41 | sanityCheck(err)
|
---|
42 | fmt.Printf("%s", body)
|
---|
43 | }
|
---|
44 | func ShowMoonPhases() {
|
---|
45 | query := url + "/Moon" + format
|
---|
46 | resp, err := http.Get(query)
|
---|
47 | sanityCheck(err)
|
---|
48 | defer resp.Body.Close()
|
---|
49 | body, err := io.ReadAll(resp.Body)
|
---|
50 | sanityCheck(err)
|
---|
51 | fmt.Printf("%s\n", body)
|
---|
52 | }
|
---|
53 | func sanityCheck(err error) {
|
---|
54 | if err != nil {
|
---|
55 | log.Fatal(err)
|
---|
56 | }
|
---|
57 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.