From 8dc07e666e0e3efef8d7cce41d8534ec3e52bf4d Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Sun, 26 Feb 2017 08:19:30 +0100 Subject: [PATCH] [modules/weather] Replace urllib with requests Since requests works the same for python2.7 and python3.x, use requests instead of urllib (which returns a string in python2.7, but byte data in python3.0, at least). --- bumblebee/modules/weather.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bumblebee/modules/weather.py b/bumblebee/modules/weather.py index 51d55c4..d145e5f 100644 --- a/bumblebee/modules/weather.py +++ b/bumblebee/modules/weather.py @@ -4,7 +4,7 @@ """Displays the temperature on the current location based on the ip Requires the following python packages: - * urllib + * requests Parameters: * weather.interval: Interval (in minutes) for updating weather information @@ -17,7 +17,7 @@ import bumblebee.output import bumblebee.engine import json import time -from urllib import urlopen +import requests class Module(bumblebee.engine.Module): def __init__(self, engine, config): @@ -52,12 +52,12 @@ class Module(bumblebee.engine.Module): weather_url = "{}&units={}".format(weather_url, self._unit) if self._location == "auto": location_url = "http://ipinfo.io/json" - location = json.loads(urlopen(location_url).read()) + location = json.loads(requests.get(location_url).text) coord = location["loc"].split(",") weather_url = "{url}&lat={lat}&lon={lon}".format(url=weather_url, lat=coord[0], lon=coord[1]) else: weather_url = "{url}&q={city}".format(url=weather_url, city=self._location) - weather = json.loads(urlopen(weather_url).read()) + weather = json.loads(requests.get(weather_url).text) self._temperature = weather['main']['temp'] self._timer += 1 return