Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace sun to moon if night time #115

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backends/forecast.io.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func (c *forecastConfig) parseDaily(hours, days forecastDataBlock, numdays int)

func (c *forecastConfig) parseCond(dp forecastDataPoint) (ret iface.Cond, err error) {
codemap := map[string]iface.WeatherCode{
"clear-day": iface.CodeSunny,
"clear-night": iface.CodeSunny,
"clear-day": iface.CodeClear,
"clear-night": iface.CodeClear,
"rain": iface.CodeLightRain,
"snow": iface.CodeLightSnow,
"sleet": iface.CodeLightSleet,
Expand Down
2 changes: 1 addition & 1 deletion backends/openweathermap.org.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (c *openWeatherConfig) parseCond(dataInfo dataBlock) (iface.Cond, error) {
762: iface.CodeUnknown, // volcanic ash
771: iface.CodeUnknown, // squalls
781: iface.CodeUnknown, // tornado
800: iface.CodeSunny,
800: iface.CodeClear,
801: iface.CodePartlyCloudy,
802: iface.CodeCloudy,
803: iface.CodeVeryCloudy,
Expand Down
2 changes: 1 addition & 1 deletion backends/worldweatheronline.com.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func wwoParseCond(cond wwoCond, date time.Time) (ret iface.Cond) {
ret.ChanceOfRainPercent = cond.TmpCor

codemap := map[int]iface.WeatherCode{
113: iface.CodeSunny,
113: iface.CodeClear,
116: iface.CodePartlyCloudy,
119: iface.CodeCloudy,
122: iface.CodeVeryCloudy,
Expand Down
80 changes: 79 additions & 1 deletion frontends/ascii-art-table.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ type aatConfig struct {
unit iface.UnitSystem
}

const (
nightTime = 22
morningTime = 6
)

//TODO: replace s parameter with printf interface?
func aatPad(s string, mustLen int) (ret string) {
ansiEsc := regexp.MustCompile("\033.*?m")
Expand Down Expand Up @@ -250,7 +255,7 @@ func (c *aatConfig) formatCond(cur []string, cond iface.Cond, current bool) (ret
"\033[38;5;226m /\033[38;5;250m(___(__) \033[0m",
" ",
},
iface.CodeSunny: {
iface.CodeClear: {
"\033[38;5;226m \\ / \033[0m",
"\033[38;5;226m .-. \033[0m",
"\033[38;5;226m ‒ ( ) ‒ \033[0m",
Expand Down Expand Up @@ -287,7 +292,80 @@ func (c *aatConfig) formatCond(cur []string, cond iface.Cond, current bool) (ret
},
}

nightCodes := map[iface.WeatherCode][]string{
iface.CodeClear: {
"\033[38;5;21m * .-\"\"-. \033[0m",
"\033[38;5;21m / \\ \033[0m",
"\033[38;5;21m | |\033[0m",
"\033[38;5;21m \\ / \033[0m",
"\033[38;5;21m * '-..-' \033[0m",
},
iface.CodePartlyCloudy: {
"\033[38;5;21m .-\"\"-. \033[0m",
"\033[38;5;21m / \033[38;5;250m.-.\033[38;5;21m \\ \033[0m",
"\033[38;5;21m | \033[38;5;250m( ).\033[38;5;21m|\033[0m",
"\033[38;5;21m \\\033[38;5;250m(___(__)\033[0m",
"\033[38;5;21m * '-..-' \033[0m",
},
iface.CodeThunderyShowers: {
"\033[38;5;21m .-\"\"-.\033[38;5;250m.-. \033[0m",
"\033[38;5;21m / \033[38;5;250m( ). \033[0m",
"\033[38;5;21m| \033[38;5;250m(___(__) \033[0m",
"\033[38;5;21;5m \\ ⚡\033[38;5;111;25mʻ ʻ\033[38;5;228;5m⚡\033[38;5;111;25mʻ ʻ \033[0m",
"\033[38;5;21m '-..-'\033[0m\033[38;5;111m ʻ ʻ \033[0m",
},
iface.CodeThunderySnowShowers: {
"\033[38;5;21m - \033[38;5;250m.-. \033[0m",
"\033[38;5;21m / \033[38;5;250m( ). \033[0m",
"\033[38;5;21m \\ \033[38;5;250m(___(__) \033[0m",
"\033[38;5;255m * *\033[38;5;228;5m⚡\033[38;5;255;25m *\033[38;5;228;5m⚡\033[38;5;255;25m * \033[0m",
"\033[38;5;255m * * * \033[0m",
},
iface.CodeHeavyShowers: {
"\033[38;5;21m /\"\"\033[38;5;240;1m.-. \033[0m",
"\033[38;5;21m \\_\033[38;5;240;1m( ). \033[0m",
"\033[38;5;21m \033[38;5;240;1m(___(__) \033[0m",
"\033[38;5;21;1m ‚ʻ‚ʻ‚ʻ‚ʻ \033[0m",
"\033[38;5;21;1m ‚ʻ‚ʻ‚ʻ‚ʻ \033[0m",
},
iface.CodeHeavySnowShowers: {
"\033[38;5;21m /\"\"\033[38;5;240;1m.-. \033[0m",
"\033[38;5;21m \\_\033[38;5;240;1m( ). \033[0m",
"\033[38;5;21m \033[38;5;240;1m(___(__) \033[0m",
"\033[38;5;255;1m * * * * \033[0m",
"\033[38;5;255;1m * * * * \033[0m",
},
iface.CodeLightShowers: {
"\033[38;5;21m /\"\"\033[38;5;240;1m.-. \033[0m",
"\033[38;5;21m \\_\033[38;5;240;1m( ). \033[0m",
"\033[38;5;21m \033[38;5;240;1m(___(__) \033[0m",
"\033[38;5;111m ʻ ʻ ʻ ʻ \033[0m",
"\033[38;5;111m ʻ ʻ ʻ ʻ \033[0m",
},
iface.CodeLightSleetShowers: {
"\033[38;5;21m /\"\"\033[38;5;240;1m.-. \033[0m",
"\033[38;5;21m \\_\033[38;5;240;1m( ). \033[0m",
"\033[38;5;21m \033[38;5;240;1m(___(__) \033[0m",
"\033[38;5;111m ʻ \033[38;5;255m*\033[38;5;111m ʻ \033[38;5;255m* \033[0m",
"\033[38;5;255m *\033[38;5;111m ʻ \033[38;5;255m*\033[38;5;111m ʻ \033[0m",
},
iface.CodeLightSnowShowers: {
"\033[38;5;21m /\"\"\033[38;5;240;1m.-. \033[0m",
"\033[38;5;21m \\_\033[38;5;240;1m( ). \033[0m",
"\033[38;5;21m \033[38;5;240;1m(___(__) \033[0m",
"\033[38;5;255m * * * \033[0m",
"\033[38;5;255m * * * \033[0m",
},
}
icon, ok := codes[cond.Code]
if cond.Time.Hour() > nightTime || cond.Time.Hour() < morningTime {
iconNigth, okNight := nightCodes[cond.Code]
if okNight {
icon = iconNigth
ok = okNight
}
}

if !ok {
log.Fatalln("aat-frontend: The following weather code has no icon:", cond.Code)
}
Expand Down
2 changes: 1 addition & 1 deletion frontends/emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c *emojiConfig) formatCond(cur []string, cond iface.Cond, current bool) (r
iface.CodeLightSnow: "🌨",
iface.CodeLightSnowShowers: "🌨",
iface.CodePartlyCloudy: "⛅️",
iface.CodeSunny: "☀️",
iface.CodeClear: "☀️",
iface.CodeThunderyHeavyRain: "🌩",
iface.CodeThunderyShowers: "⛈",
iface.CodeThunderySnowShowers: "⛈",
Expand Down
2 changes: 1 addition & 1 deletion iface/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
CodeLightSnow
CodeLightSnowShowers
CodePartlyCloudy
CodeSunny
CodeClear
CodeThunderyHeavyRain
CodeThunderyShowers
CodeThunderySnowShowers
Expand Down