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