added emoji support

master
Simon Kellet 2 years ago
parent aeb64a0579
commit 2e265618d3
  1. BIN
      go-weather
  2. 11
      go.mod
  3. 16
      go.sum
  4. 57
      main.go

Binary file not shown.

@ -1,3 +1,14 @@
module go-weather
go 1.17
require (
github.com/fatih/color v1.13.0
github.com/kyokomi/emoji v2.2.4+incompatible
)
require (
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
)

@ -0,0 +1,16 @@
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/kyokomi/emoji v2.2.4+incompatible h1:np0woGKwx9LiHAQmwZx79Oc0rHpNw3o+3evou4BEPv4=
github.com/kyokomi/emoji v2.2.4+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2pxoszVseX1DNoGtU2tBA=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

@ -11,7 +11,7 @@ import (
"time"
"github.com/fatih/color"
"github.com/sami2020pro/gmoji"
"github.com/kyokomi/emoji"
)
type WeatherAPI struct {
@ -90,12 +90,11 @@ func main() {
//Create file
createFile(string(html), false)
//Load the file
data, _ := loadJson("weather.json")
//print the weather!
//Print the weather!
printWeather(data)
color.Cyan("Prints text in cyan.")
color.Red("Hello!")
fmt.Printf("Hello %v\n", gmoji.Fire)
}
func loadJson(file string) (WeatherAPI, error) {
@ -141,25 +140,39 @@ func loadWebPage(web_url string) ([]byte, error) {
}
/*
func iconToEmoji(icon string) (emoji string) {
func iconToEmoji(icon string) {
var em string
switch icon {
case "Clouds":
em = ":cloud:"
case "Drizzle":
em = ":rain:"
case "Rain":
em = ":rain:"
case "Snow":
em = ":snow:"
case "Clear":
em = ":sun:"
default:
em = ":sun"
}
emoji.Printf(em)
}
*/
func printWeather(data WeatherAPI) {
weatherData := data
whilte := color.New(color.FgWhite)
boldWhite := whilte.Add(color.Bold)
dt := time.Now()
fmt.Println(dt.Format("01/02/2006 15:04"))
white := color.New(color.FgWhite)
boldWhite := white.Add(color.Bold)
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
@ -167,13 +180,15 @@ func printWeather(data WeatherAPI) {
str_sunset := time.Unix(weatherData.Sys.Sunset, 0)
str_sunrise := time.Unix(weatherData.Sys.Sunrise, 0)
boldWhite.Printf("Location: %v, %v\n"+
"Weather: %v (%v)\n"+
"Temp: %v°C (Feels like: %v°C)\n(Min: %v°C, Max: %v°C)\n"+
"Sunrise: %v\t"+
"Sunset: %v\n",
str_loc, str_code,
str_weather, str_weather_detail,
str_temp, str_temp_fl, str_temp_min, str_temp_max,
str_sunrise.Format("15:04"), str_sunset.Format("15:04"))
boldWhite.Printf("Location: ")
fmt.Printf("%v, %v\n", str_loc, str_code)
boldWhite.Printf("Weather: ")
iconToEmoji(str_weather_icon)
fmt.Printf(" %v (%v)\n", str_weather, str_weather_detail)
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)
boldWhite.Printf("Sunrise: ")
fmt.Printf("%v\t", str_sunrise.Format("15:04"))
boldWhite.Printf("Sunset: ")
fmt.Printf("%v\n", str_sunset.Format("15:04"))
}

Loading…
Cancel
Save