aboutsummaryrefslogtreecommitdiff
path: root/modules/weather.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-04-28 12:11:23 +0100
committerGravatar jesopo2019-04-28 12:11:23 +0100
commitcbed30ed620bfff023be24eb1f0816bed090026d (patch)
tree04a005f57d00da9470c530ac8342058cd3dcd2a1 /modules/weather.py
parentRemove debug print (diff)
Change location.py to use geocoding, change weather.py in line with it
Diffstat (limited to 'modules/weather.py')
-rw-r--r--modules/weather.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/modules/weather.py b/modules/weather.py
index ddf7a1a6..4c217944 100644
--- a/modules/weather.py
+++ b/modules/weather.py
@@ -5,15 +5,32 @@ from src import ModuleManager, utils
URL_WEATHER = "http://api.openweathermap.org/data/2.5/weather"
class Module(ModuleManager.BaseModule):
- @utils.hook("received.command.weather", min_args=1, usage="<location>")
+ def _user_location(self, user):
+ user_location = user.get_setting("location", None)
+ if not user_location == None:
+ return "%s, %s" % (user_location["city"], user_location["country"])
+
+ @utils.hook("received.command.weather", usage="<location>")
def weather(self, event):
"""
- :help: Get current weather data for a provided location
- :usage: <location>
+ :help: Get current weather for you or someone else
+ :usage: [nickname]
"""
api_key = self.bot.config["openweathermap-api-key"]
+
+ location = None
+ if event["args"]:
+ target_user = event["server"].get_user(event["args_split"][0])
+ location = self._user_location(target_user)
+ if location == None:
+ raise utils.EventError("%s doesn't have a location set")
+ else:
+ location = self._user_location(event["user"])
+ if location == None:
+ raise utils.EventError("You don't have a location set")
+
page = utils.http.request(URL_WEATHER, get_params={
- "q": event["args"], "units": "metric",
+ "q": location, "units": "metric",
"APPID": api_key},
json=True)
if page: