Skip to content

Commit

Permalink
Improve weather reply
Browse files Browse the repository at this point in the history
  • Loading branch information
bbriggs committed Jan 25, 2024
1 parent 6fbdd04 commit a586d2d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lambdas.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"
"hash/crc64"
"io"
"io/ioutil"
"math/rand"
"net/http"
"net/url"
Expand Down Expand Up @@ -39,7 +39,7 @@ func weatherLambda(ctx context.Context, rdb *redis.Client, topic *pubsubDiscordT
log.Warn().Err(err).Str("city", city).Msg("Error fetching weather data")
content = fmt.Sprintf("Error fetching weather data for %s: %v", city, err)
} else {
content = fmt.Sprintf("The weather in %s is %s", city, weather)
content = weather
}
}

Expand Down Expand Up @@ -112,14 +112,14 @@ func epeen(m discordgo.Message) string {
}

func getWeather(city string) (string, error) {
apiURL := fmt.Sprintf("https://wttr.in/%s?format=%%C|%%t|%%w", url.QueryEscape(city))
apiURL := fmt.Sprintf("https://wttr.in/%s?format=2", url.QueryEscape(city)) // format=2 is a preconfigured format for a single line of weather data. 3 and 4 include the city name with ugly + signs as delimiters
resp, err := http.Get(apiURL)
if err != nil {
return "", fmt.Errorf("failed to fetch weather data: %v", err)
}
defer resp.Body.Close()

body, err := io.ReadAll(resp.Body)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("failed to read response body: %v", err)
}
Expand Down

0 comments on commit a586d2d

Please sign in to comment.