nate-parrott / Flashlight

The missing Spotlight plugin system
http://flashlight.nateparrott.com
Other
5.39k stars 411 forks source link

Weather: Localise address and add option to select units. #475

Closed cHemingway closed 9 years ago

cHemingway commented 9 years ago

Fixes #473 Fixes #434

This commit fixes the problem of getting weather for the correct city, as the current plugin does not give preference to locations that are "local".

It does this by fetching all locations that match the search, then selecting those with the correct country code. If this cannot be found, it returns the first result. This results in two API request, one to fetch search results, and one to get the weather for a particular result. This slows the plugin somewhat, but I cannot find any alternatives. A possible future improvement might be to "cache" the locationID from previous searches.

The country code is either set by the locale, or can be appended to the search (e.g. London,CA) to override it.

This pull request also adds in the option to select the units used, though the default is to automatically set them from the locale as before.