llimllib / limbo

A simple, clean, easy to modify Slack chatbot
MIT License
402 stars 160 forks source link

Replace Dark Sky with OpenWeather. #182

Closed rdimartino closed 4 years ago

rdimartino commented 4 years ago

Resolves #181

OpenWeather does not have a daily forecast in the free tier, so this only returns the current day's temp and icon.

Haven't tested it because I don't have a running instance of limbo, but I think it's basically the same as the Dark Sky version (except it's only one day as noted).

❯ python -c "from weather import weather; print(weather('cincinnati, oh'))"
('Weather for Cincinnati, Ohio, United States: ', [{'title': 'Thursday', 'value': ':sun_behind_cloud: 49°f', 'short': True}])
llimllib commented 4 years ago

I'm probably not going to accept a PR with only a one-day forecast; if the free weather APIs are not acceptable I'd rather just scrape a web page

eSoares commented 4 years ago

From the pricing page it says that Free API supports "5 days/3 hour forecast API", it should be possible?

rdimartino commented 4 years ago

@eSoares Yeah, but it just gives you the next forty 3-hour forecasts all in UTC time. I thought about trying to use the forecast at noon (or some other time) on each day, but the response doesn't have any timezone information (and the mapbox response doesn't either AFAICT). I wasn't sure how to best get a daily forecast from that. One option might be to pick a UTC time of day to use as that day's forecast, but that definitely has issues. Another option would be to make two requests to OpenWeather. The first for today's forecast (which has a response that does include the tz) and the second for the 5 day forecast. Not sure if two requests (three if you count mapbox) per message was too many.

rdimartino commented 4 years ago

Not really an ideal solution (scraping may still be the answer) but I think this is essentially how you could do four days of weather with the OpenWeather API

❯ python -c "from weather import weather; print(weather('cincinnati, oh'))"
('Weather for Cincinnati, Ohio, United States: ', [{'title': 'Thursday', 'value': ':sun_behind_cloud: 53°f', 'short': True}, {'title': 'Friday', 'value': ':sunny: 66°f', 'short': True}, {'title': 'Saturday', 'value': ':cloud: 66°f', 'short': True}, {'title': 'Sunday', 'value': ':cloud: 65°f', 'short': True}])