Closed moritzheiber closed 3 years ago
Okay, one thing, could you visit https://wttr.in in a regular browser and post a screenshot?
And what happens if you set the weather_location
inside the blocklet configuration?
kgilmer@clavin:/tmp/regolith-i3xrocks-config/scripts$ weather_location="Lake Forest, CA" ./weather
<span font_desc="JetBrains Mono Medium 13" color="#E6E1CF">☀️ +57°F</span>
kgilmer@clavin:/tmp/regolith-i3xrocks-config/scripts$ weather_location="Toronto, CA" ./weather
<span font_desc="JetBrains Mono Medium 13" color="#E6E1CF">☁️ +37°F</span>
kgilmer@clavin:/tmp/regolith-i3xrocks-config/scripts$ ./weather
<span font_desc="JetBrains Mono Medium 13" color="#E6E1CF">☀️ +50°F</span>
kgilmer@clavin:/tmp/regolith-i3xrocks-config/scripts$
kgilmer@clavin:/tmp/regolith-i3xrocks-config/scripts$ ./weather
<span font_desc="JetBrains Mono Medium 13" color="#E6E1CF">☀️ +50°F</span>
It seems to be working today..? I notice though that the default location temp seems to be different than if I specify my town specifically. Given that we can't really depend on the service to return valid data, we need a better way of handing error cases. I think this was tried in the past but I guess the heuristic didn't work out.
As I recall, I think there is something volatile about wttr, like a limited amount of location resolution per day based on free API usage, although I may be dreaming that up.
I've read up on wttr.in and how reliable it is and since the release of their latest API (v3
) they seem to have resolved to rate limiting issues at least (they're not querying several services by default). Nonetheless, I've added a way of handling the "Unknown location" errors more gracefully. I don't think we can resolve them better with the current implementation.
I thought about switching away from wttr.in, to e.g. GWeather (which comes with its own slew of problems, mainly its lacking location database) or yr.no (which then needs accurate location information retrieved in the script, again), but found none of them attainable.
@kgilmer Does the script in its current state work for you? I'm going to add some documentation to the website to address the most common issues (e.g. setting your location manually)
Indeed it does! I am good w/ this change.
$ scripts/weather
<span font_desc="JetBrains Mono Medium 13" color="#E6E1CF">☀️ +52°F</span>
Here's a (opinionated) rewrite of the weather blocklet:
weather_location
to something sensible.weather_unit
variable to eitheru
(for USCS) orm
(for metric) to override this behavior.urlencode
function in bash. There are a thousand edge cases and I don't want to support all of them just for a small blocklet. Instead, IF (and that's a big if) the wttr.in autodetection doesn't work folks can choose to specify their location using thequery
parameter WorldWeatherOnline supports (which wttr.in uses for their own API). E.g.São Paulo
would becomeweather_location=São+Paulo
(yes, in Unicode, wttr.in supports that!), and if that doesn't return a satisfying result you can even specify a country (e.g.London,uk
) or a UK/Canada postal/US zipcode (90201
). Yes, this is a little more complicated for the individual user, but we're talking about highly unlikely edge-case here and I don't want to optimize a very simple script for these edge-cases.I've also added fairly exhaustive tests. Obviously, they don't cover all the use-cases, but my intent is to add more of them as they appear (and break the script). For now all of the test cases should be passing.
Fixes #95
cc @hendynz @p3k