Skip to content

Commit

Permalink
fix: add space between times at alert
Browse files Browse the repository at this point in the history
feat: add location to .env var
  • Loading branch information
remi-espie committed Jun 22, 2023
1 parent 1e92318 commit 260ad12
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ WEBHOOK_URL=[some discord webhook]
AVATAR_URL=[some image url]
OWM_KEY=[some OpenWeatherMap api key]
LONGITUDE=[some longitude coordinates]
LATITUDE=[some latitude coordinates]
LATITUDE=[some latitude coordinates]
LOCATION=[Some time location ("Europe/Paris")]
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

.env
output/.env

.idea

Expand Down
12 changes: 7 additions & 5 deletions weather.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func getWeather() string {
log.Fatal("Error converting latitude:", err)
}

location := os.Getenv("LOCATION")

coord := &owm.Coordinates{
Longitude: long,
Latitude: lat,
Expand All @@ -46,10 +48,10 @@ func getWeather() string {
log.Fatal(err)
}

return parseWeather(forecast.Daily[0], forecast.Alerts)
return parseWeather(forecast.Daily[0], forecast.Alerts, location)
}

func parseWeather(forecast owm.OneCallDailyData, alerts []owm.OneCallAlertData) string {
func parseWeather(forecast owm.OneCallDailyData, alerts []owm.OneCallAlertData, location string) string {
weatherType := forecast.Weather[0].Main
weatherEmoji := ""
switch weatherType {
Expand Down Expand Up @@ -86,15 +88,15 @@ func parseWeather(forecast owm.OneCallDailyData, alerts []owm.OneCallAlertData)

if len(alerts) > 0 {

location, err := time.LoadLocation("Europe/Paris")
location, err := time.LoadLocation(location)
if err != nil {
log.Fatalf("Error loading time")
}

for _, alert := range alerts {
output += "\n🚨 " + alert.Event
output += " from" + time.Unix(int64(alert.Start), 0).In(location).Format("15:04")
output += " to" + time.Unix(int64(alert.End), 0).In(location).Format("15:04")
output += " from " + time.Unix(int64(alert.Start), 0).In(location).Format("15:04")
output += " to " + time.Unix(int64(alert.End), 0).In(location).Format("15:04")
output += " !"
}
}
Expand Down

0 comments on commit 260ad12

Please sign in to comment.