[modules/weather] double quotes to single quotes

This commit is contained in:
Tobias Witek 2020-03-15 14:05:26 +01:00
parent 633bbdd6ff
commit 0e538a6088

View file

@ -1,7 +1,7 @@
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
# pylint: disable=C0111,R0903 # pylint: disable=C0111,R0903
"""Displays the temperature on the current location based on the ip '''Displays the temperature on the current location based on the ip
Requires the following python packages: Requires the following python packages:
* requests * requests
@ -14,7 +14,7 @@ Parameters:
* weather.showcity: If set to true, show location information, otherwise hide it (defaults to true) * weather.showcity: If set to true, show location information, otherwise hide it (defaults to true)
* weather.showminmax: If set to true, show the minimum and maximum temperature, otherwise hide it (defaults to false) * weather.showminmax: If set to true, show the minimum and maximum temperature, otherwise hide it (defaults to false)
* weather.apikey: API key from http://api.openweathermap.org * weather.apikey: API key from http://api.openweathermap.org
""" '''
import bumblebee.input import bumblebee.input
import bumblebee.output import bumblebee.output
@ -33,16 +33,16 @@ class Module(bumblebee.engine.Module):
bumblebee.output.Widget(full_text=self.output) bumblebee.output.Widget(full_text=self.output)
) )
self._temperature = 0 self._temperature = 0
self._apikey = self.parameter("apikey", "af7bfe22287c652d032a3064ffa44088") self._apikey = self.parameter('apikey', 'af7bfe22287c652d032a3064ffa44088')
self._location = self.parameter("location", "auto") self._location = self.parameter('location', 'auto')
if "," in self._location: if ',' in self._location:
self._location = self._location.split(",") self._location = self._location.split(',')
else: else:
self._location = [self._location] self._location = [self._location]
self._index = 0 self._index = 0
self._showcity = bumblebee.util.asbool(self.parameter("showcity", True)) self._showcity = bumblebee.util.asbool(self.parameter('showcity', True))
self._showminmax = bumblebee.util.asbool(self.parameter("showminmax", False)) self._showminmax = bumblebee.util.asbool(self.parameter('showminmax', False))
self._unit = self.parameter("unit", "metric") self._unit = self.parameter('unit', 'metric')
self._valid = False self._valid = False
self.interval_factor(60) self.interval_factor(60)
self.interval(15) self.interval(15)
@ -59,33 +59,33 @@ class Module(bumblebee.engine.Module):
self.update(self.widgets()) self.update(self.widgets())
def _unit_suffix(self): def _unit_suffix(self):
if self._unit == "metric": if self._unit == 'metric':
return "C" return 'C'
if self._unit == "kelvin": if self._unit == 'kelvin':
return "K" return 'K'
if self._unit == "imperial": if self._unit == 'imperial':
return "F" return 'F'
return "" return ''
def temperature(self): def temperature(self):
return u"{}°{}".format(self._temperature, self._unit_suffix()) return u'{}°{}'.format(self._temperature, self._unit_suffix())
def tempmin(self): def tempmin(self):
return u"{}°{}".format(self._tempmin, self._unit_suffix()) return u'{}°{}'.format(self._tempmin, self._unit_suffix())
def tempmax(self): def tempmax(self):
return u"{}°{}".format(self._tempmax, self._unit_suffix()) return u'{}°{}'.format(self._tempmax, self._unit_suffix())
def city(self): def city(self):
city = re.sub('[_-]', ' ', self._city) city = re.sub('[_-]', ' ', self._city)
return u"{} ".format(city) return u'{} '.format(city)
def output(self, widget): def output(self, widget):
if not self._valid: if not self._valid:
return u"?" return u'?'
if self._showminmax: if self._showminmax:
self._showcity=False self._showcity=False
return self.city() + self.temperature() + " Hi:" + self.tempmax() + " Lo:" + self.tempmin() return self.city() + self.temperature() + ' Hi:' + self.tempmax() + ' Lo:' + self.tempmin()
elif self._showcity: elif self._showcity:
return self.city() + self.temperature() return self.city() + self.temperature()
else: else:
@ -93,19 +93,19 @@ class Module(bumblebee.engine.Module):
def state(self, widget): def state(self, widget):
if self._valid: if self._valid:
if "thunderstorm" in self._weather: if 'thunderstorm' in self._weather:
return ['thunder'] return ['thunder']
elif "drizzle" in self._weather: elif 'drizzle' in self._weather:
return ['rain'] return ['rain']
elif "rain" in self._weather: elif 'rain' in self._weather:
return ['rain'] return ['rain']
elif "snow" in self._weather: elif 'snow' in self._weather:
return ['snow'] return ['snow']
elif "sleet" in self._weather: elif 'sleet' in self._weather:
return ['sleet'] return ['sleet']
elif "clear" in self._weather: elif 'clear' in self._weather:
return ['clear'] return ['clear']
elif "cloud" in self._weather: elif 'cloud' in self._weather:
return ['clouds'] return ['clouds']
else: else:
return [] return []
@ -114,17 +114,17 @@ class Module(bumblebee.engine.Module):
def update(self, widgets): def update(self, widgets):
try: try:
weather_url = "http://api.openweathermap.org/data/2.5/weather?appid={}".format(self._apikey) weather_url = 'http://api.openweathermap.org/data/2.5/weather?appid={}'.format(self._apikey)
weather_url = "{}&units={}".format(weather_url, self._unit) weather_url = '{}&units={}'.format(weather_url, self._unit)
if self._location[self._index] == "auto": if self._location[self._index] == 'auto':
location_url = "http://ipinfo.io/json" location_url = 'http://ipinfo.io/json'
location = requests.get(location_url).json() location = requests.get(location_url).json()
coord = location["loc"].split(",") coord = location['loc'].split(',')
weather_url = "{url}&lat={lat}&lon={lon}".format(url=weather_url, lat=coord[0], lon=coord[1]) weather_url = '{url}&lat={lat}&lon={lon}'.format(url=weather_url, lat=coord[0], lon=coord[1])
elif self._location[self._index].isdigit(): elif self._location[self._index].isdigit():
weather_url = "{url}&id={id}".format(url=weather_url, id=self._location[self._index]) weather_url = '{url}&id={id}'.format(url=weather_url, id=self._location[self._index])
else: else:
weather_url = "{url}&q={city}".format(url=weather_url, city=self._location[self._index]) weather_url = '{url}&q={city}'.format(url=weather_url, city=self._location[self._index])
weather = requests.get(weather_url).json() weather = requests.get(weather_url).json()
self._city = weather['name'] self._city = weather['name']
self._temperature = int(weather['main']['temp']) self._temperature = int(weather['main']['temp'])