tweaks and fixes
This commit is contained in:
+33
-28
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
// WeatherAPI ...
|
||||
type WeatherAPI struct {
|
||||
Coord Coord `json:"coord"`
|
||||
Weather []Weather `json:"weather"`
|
||||
@@ -24,11 +25,13 @@ type WeatherAPI struct {
|
||||
COD int `json:"cod"`
|
||||
}
|
||||
|
||||
// Coord ...
|
||||
type Coord struct {
|
||||
Lon float64 `json:"lon"`
|
||||
Lat float64 `json:"lat"`
|
||||
}
|
||||
|
||||
// Weather ...
|
||||
type Weather struct {
|
||||
ID int `json:"id"`
|
||||
Main string `json:"main"`
|
||||
@@ -36,32 +39,37 @@ type Weather struct {
|
||||
Icon string `json:"icon"`
|
||||
}
|
||||
|
||||
// Main ...
|
||||
type Main struct {
|
||||
Temp float64 `json:"temp"`
|
||||
Feels_like float64 `json:"feels_like"`
|
||||
Temp_min float64 `json:"temp_min"`
|
||||
Temp_max float64 `json:"temp_max"`
|
||||
Pressure float64 `json:"pressure"`
|
||||
Humidity float64 `json:"humidity"`
|
||||
Temp float64 `json:"temp"`
|
||||
FeelsLike float64 `json:"feels_like"`
|
||||
TempMin float64 `json:"temp_min"`
|
||||
TempMax float64 `json:"temp_max"`
|
||||
Pressure float64 `json:"pressure"`
|
||||
Humidity float64 `json:"humidity"`
|
||||
}
|
||||
|
||||
// Wind ...
|
||||
type Wind struct {
|
||||
Speed float64 `json:"speed"`
|
||||
Deg float64 `json:"deg"`
|
||||
Gust float64 `json:"gust"`
|
||||
}
|
||||
|
||||
// Rain ...
|
||||
type Rain struct {
|
||||
T1h float64 `json:"1h"`
|
||||
}
|
||||
|
||||
// Cloud ...
|
||||
type Cloud struct {
|
||||
All int `json:"all"`
|
||||
}
|
||||
|
||||
// Sys ...
|
||||
type Sys struct {
|
||||
Types int `json:"type"`
|
||||
Id int64 `json:"id"`
|
||||
ID int64 `json:"id"`
|
||||
Country string `json:"country"`
|
||||
Sunrise int64 `json:"sunrise"`
|
||||
Sunset int64 `json:"sunset"`
|
||||
@@ -88,7 +96,7 @@ func iconToEmoji(icon string) {
|
||||
case "Thunderstorm":
|
||||
emoji = "⛈"
|
||||
default:
|
||||
emoji = "️❓"
|
||||
emoji = ""
|
||||
}
|
||||
fmt.Print(emoji)
|
||||
}
|
||||
@@ -102,33 +110,30 @@ func printWeather(data WeatherAPI) {
|
||||
dt := time.Now()
|
||||
boldWhite.Println(dt.Format("01/02/2006 15:04"))
|
||||
|
||||
str_loc := weatherData.Name
|
||||
str_code := weatherData.Sys.Country
|
||||
str_weather := weatherData.Weather[0].Main
|
||||
str_weather_detail := weatherData.Weather[0].Description
|
||||
str_weather_icon := weatherData.Weather[0].Main
|
||||
str_temp := weatherData.Main.Temp
|
||||
str_temp_fl := weatherData.Main.Feels_like
|
||||
str_temp_min := weatherData.Main.Temp_min
|
||||
str_temp_max := weatherData.Main.Temp_max
|
||||
str_sunset := time.Unix(weatherData.Sys.Sunset, 0)
|
||||
str_sunrise := time.Unix(weatherData.Sys.Sunrise, 0)
|
||||
//str_wind_speed := weatherData.Wind.Speed
|
||||
strLoc := weatherData.Name
|
||||
strCode := weatherData.Sys.Country
|
||||
strWeather := weatherData.Weather[0].Main
|
||||
strWeatherDetail := weatherData.Weather[0].Description
|
||||
strWeatherIcon := weatherData.Weather[0].Main
|
||||
strTemp := weatherData.Main.Temp
|
||||
strTempFl := weatherData.Main.FeelsLike
|
||||
strTempMin := weatherData.Main.TempMin
|
||||
strTempMax := weatherData.Main.TempMax
|
||||
strSunset := time.Unix(weatherData.Sys.Sunset, 0)
|
||||
strSunrise := time.Unix(weatherData.Sys.Sunrise, 0)
|
||||
|
||||
boldWhite.Printf("📍Location: ")
|
||||
fmt.Printf("%v, %v\n", str_loc, str_code)
|
||||
fmt.Printf("%v, %v\n", strLoc, strCode)
|
||||
|
||||
boldWhite.Printf("Weather:")
|
||||
iconToEmoji(str_weather_icon)
|
||||
fmt.Printf(" %v (%v)\n", str_weather, str_weather_detail)
|
||||
iconToEmoji(strWeatherIcon)
|
||||
fmt.Printf(" %v (%v)\n", strWeather, strWeatherDetail)
|
||||
|
||||
boldWhite.Printf("🌡️ Temp: ")
|
||||
fmt.Printf("%v°C (Feels like: %v°C)\n(Min: %v°C, Max: %v°C)\n", str_temp, str_temp_fl, str_temp_min, str_temp_max)
|
||||
fmt.Printf("%v°C (Feels like: %v°C)\n(Min: %v°C, Max: %v°C)\n", strTemp, strTempFl, strTempMin, strTempMax)
|
||||
|
||||
boldWhite.Printf("🌅Sunrise: ")
|
||||
fmt.Printf("%v\t", str_sunrise.Format("15:04"))
|
||||
fmt.Printf("%v\t", strSunrise.Format("15:04"))
|
||||
boldWhite.Printf("🌇Sunset: ")
|
||||
|
||||
fmt.Printf("%v\n", str_sunset.Format("15:04"))
|
||||
//fmt.Printf("Wind Speed: %vm/s", str_wind_speed)
|
||||
fmt.Printf("%v\n", strSunset.Format("15:04"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user