4 class OpenWeatherMapError(RuntimeError):
8 def openweathermap_json(apikey, cityid):
9 """Returns parsed JSON as returned by openweathermap for the given cityid.
10 In case of errors, an OpenWeatherMapError is raised."""
11 baseurl = 'http://api.openweathermap.org/data/2.5/weather'
12 query = baseurl + '?units=metric&APPID={}&id={}&lang=de'.format(apikey, cityid)
14 response = requests.get(query)
15 if response.status_code != 200:
16 raise OpenWeatherMapError('Got status code {} ({}).'.format(response.status_code, response.reason))
18 return response.json()
19 except requests.exceptions.RequestException as error:
20 raise OpenWeatherMapError('Request not successful: {}'.format(error))