Giter VIP home page Giter VIP logo

sopel-openweathermap's Introduction

Sopel OpenWeatherMap

An OpenWeatherMap module for looking up the weather using the Sopel IRC bot

Installation

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

Configuration

The plugin has several configuration options with sensible defaults.

api_key

Type: string

Mandatory option that must be specified in the configuration file. Get your API key from OpenWeatherMap.

enable_air_quality

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.

enable_location_best_guess

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.

HOWTO

  1. Retrieve an API key from OpenWeatherMap

  2. Run the sopel configuration option to set up the module in the bot:

    sopel -w
  3. 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

Alternative Configuration

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

Usage

The OpenWeatherMap API retrieves information based on the supplied location. There are three ways to request a location:

  1. 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
  2. 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
  3. 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

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.

Testing

Tests are run via Python unittests and are stored in the tests/ directory.

python -m unittest

sopel-openweathermap's People

Contributors

davidpirogov avatar rhinosf1 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

rhinosf1

sopel-openweathermap's Issues

setlocation breaks on capitalisation

.setlocation stockholm
user: Please refine your location by adding a country code. Valid options are: 'Stockholm,SE', 'Stockholm,US'
.setlocation Stockholm
AttributeError: 'dict' object has no attribute 'get_name' (file "....sopel/modules/owm-weather.py", line 80, in setlocation)

Probable fix in line 56 with

location_lookup = str(trigger.group(2)).lower()

Unsure if this is a path issue

I had some recent permission issues due to which I uninstalled all pip3 programs and reinstalled sopel and owm.

$ python3 owm-weather.py 5bd76b1e01f571e61e91930214ab3357 --location="Melbourne,AU"
python3: can't open file 'owm-weather.py': [Errno 2] No such file or directory

$ sudo find . / -name owm-weather.py
./.local/lib/python3.6/site-packages/sopel/modules/owm-weather.py
/usr/home/strykar/.local/lib/python3.6/site-packages/sopel/modules/owm-weather.py

strykar@phreedom:~$ echo $PATH
/home/strykar/.local/lib:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/strykar/bin:/home/strykar/.local/bin

$ ls -l /home
lrwxr-xr-x  1 root  wheel  8 Jul  9  2017 /home -> usr/home

$ python3 /usr/home/strykar/.local/lib/python3.6/site-packages/sopel/modules/owm-weather.py xxx-APIxxxx --location="Melbourne,AU"
Looking up weather for location 'Melbourne,AU'
Melbourne,AU: light intensity shower rain 14.7°C (58.4°F) Humidity: 71% Fresh breeze 11.3m/s (↓) UV Index 1.6 (low at local solar noon)
Getting locations for location 'Melbourne,AU'
Melbourne,AU has place id 2158177

/home/strykar/.local/lib is in my PATH. Where do I start to troubleshoot this?

Update wording of ambiguous search term

The wording for when an ambiguous search term is confusing.

This is due to issues with the OpenWeatherMap API and the OpenWeatherMap data quality.

Needs to be reworded to make sense for the user's intent.

LOC_COLLISION_MSG = "There are multiple results for '{}'. Visit " \
"https://openweathermap.org/find?q={} to find the right city. You can then " \
"use either the geo coords or the city id to reference the right '{}'"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.