-
Notifications
You must be signed in to change notification settings - Fork 0
/
yigo.go
executable file
·95 lines (85 loc) · 2.54 KB
/
yigo.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
)
type Weather struct {
Location struct {
Name string `json:"name"`
Region string `json:"region"`
Country string `json:"country"`
} `json:"location"`
Current struct {
LastUpdatedEpoch int `json:"last_updated_epoch"`
LastUpdated string `json:"last_updated"`
TempC float64 `json:"temp_c"`
TempF float64 `json:"temp_f"`
IsDay int `json:"is_day"`
Condition struct {
Text string `json:"text"`
Icon string `json:"icon"`
Code int `json:"code"`
} `json:"condition"`
} `json:"current"`
}
func getWeather(cityI string) (Weathers Weather) {
fileReadApiKey, fileErr := os.ReadFile("store/APIKEY.txt")
if fileErr != nil {
log.Fatal(fileErr)
}
api_link := "https://api.weatherapi.com/v1/current.json?key="
full_link := api_link + string(fileReadApiKey) + "&q=" + cityI + "&aqi=yes"
response, err := http.Get(full_link)
if err != nil {
log.Fatal(err)
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
var responseObject Weather
err = json.Unmarshal(responseData, &responseObject)
if err != nil {
fmt.Println("error:", err)
}
return responseObject
}
func printWeather(Weathers Weather, sigo string, note string) {
fmt.Printf("\nCITY: %v, %v\nTEMP: %vf / %vc \nSIGO: %v \n", Weathers.Location.Name, Weathers.Location.Country, Weathers.Current.TempF, Weathers.Current.TempC, sigo)
fmt.Printf("\nNote: %v \n\n", note)
}
func WriteToFile(addCmd *flag.FlagSet, cityweather *string) {
err := ioutil.WriteFile("store/storedcity.txt", []byte(*cityweather), 0644)
if err != nil {
log.Fatal(err)
}
}
func checkTemp(temp int) (sigo string, noteO string) {
if temp < 10 {
return "NO", "Stay in your house if you want to survive"
} else if temp < 20 {
return "Noooo", "You're going to freeze to death!"
} else if temp < 30 {
return "No", "You should put on a scarf"
} else if temp < 40 {
return "Maybe", "It's cold, but if you want to then go for it"
} else if temp < 50 {
return "Yes", "Make sure to wear some long clothing"
} else if temp < 65 {
return "Yes", "Enjoy the chill weather ;)"
} else if temp <= 80 {
return "Yes", "It's nice out, go out there :)"
} else if temp <= 90 {
return "Yes", "Beach weather, go get that tan!"
} else if temp <= 96 {
return "No", "It's very hot, up to you if you would like to get sweaty"
} else if temp <= 105 {
return "NOO", "Our planet will try up soon, do not go outside!"
}
return "maybe", "eh"
}