An OpenWeatherMap module for looking up the weather using the Sopel IRC bot
Tested on Ubuntu 20.04 LTS. Requires python 3.7, pyowm v3, and Sopel 7.1
Highly recommended to create a separate pyenv environment for the Sopel bot and use pip to install the repository. The plugin will be available to Sopel as an Entry point plugin
pyenv virtualenv sopel_7_1
pip install sopel
cd .../sopel-openweathermap
pip install .
pip install -r requirements.txt
The plugin has several configuration options with sensible defaults.
Type: string
Mandatory option that must be specified in the configuration file. Get your API key from OpenWeatherMap.
Type: bool
(True or False)
Default: False
Whether or not to enable the Air Quality measurement for the weather message. Ensure that you have an up to date version of PyOWM that has correct air quality APIs.
Type: bool
(True or False)
Default: True
Whether or not to enable a location best guess attempt when there are multiple, identical results
for the same city,country combination. Due to OpenWeatherMap data quality issues, setting this
option to True
returns a temperature range with a link to find the correct place id. Setting
this option to False
makes the user choose a correct place id.
-
Retrieve an API key from OpenWeatherMap
-
Run the sopel configuration option to set up the module in the bot:
sopel -w
-
Disable the existing, non-functioning Sopel weather module by editing the default.cfg file and adding/appending to the core exclude list
[core]
...
exclude=weather
For those who don't like running interactive sopel -w
you need to add to the default.cfg file
the following with your OWM API Key or APPID
[owm]
api_key=...
enable_air_quality=False
enable_location_best_guess=True
The OpenWeatherMap API retrieves information based on the supplied location. There are three ways to request a location:
- A unique, numeric id that is the most accurate way to express a location
- For example, London,GB has the id of
2643743
, which can be extracted from the API or from the URL
- For example, London,GB has the id of
- A geo coordinate in the form of decimal latitude,longitude
- Latitude and Longitude must be a decimal within the valid ranges
- Permitted separators are semi-colon
;
and comma,
- For compatibility with the OpenWeatherMap website, any square brackets around the geo coordinates are stripped out
- Text that represents a city, country pair. There are several caveats
- Cities in the US need to use the city, 2-letter US state abbreviation
- Cities outside of the US need to use the city, 2-letter Country abbreviation
- To search for a city name with exact match to the search term, use the
!
character before the city name. For example,!London,GB
- To search for a city that contains the search term, use the
*
character before the city name. For example,*London,GB
IRC commands for retrieving the weather from OpenWeatherMap are:
.weather Melbourne,AU
.weather New York
.weather 1850147 // Unique ID of Tokyo, JP
.weather 24.4667, 54.3667 // Closest city is Abu Dhabi, AE
You can also use .weather
without specifying anything if you have previously taught the bot your location via .setlocation
.
For example:
.setlocation New York
Note: The .setlocation
command works on the basis of your nickname, meaning that changes to nickname require an additional .setlocation
to be called.
Tests are run via Python unittests and are stored in the tests/
directory.
python -m unittest