weather-cli
weather-cli copied to clipboard
Broken: open weather map now requires an API key
The app fails to get the weather data, since open weather map now requires an API key. They are free.
I don't know python well, but I'm sure I can muddle my way through it given some time to sort out the changes; once I get there I'll make a PR, unless someone else beats me to it.
Here's the error.
Traceback (most recent call last):
File "/usr/local/bin/weather", line 6, in <module>
Weather.main()
File "/usr/local/lib/python2.7/site-packages/weathercli.py", line 146, in main
conditions = weather_provider.now(args['query'], args['units'])
File "/usr/local/lib/python2.7/site-packages/weathercli.py", line 50, in now
units
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 87, in urlopen
return opener.open(url)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 213, in open
return getattr(self, name)(url)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 364, in open_http
return self.http_error(url, fp, errcode, errmsg, headers)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 377, in http_error
result = method(url, fp, errcode, errmsg, headers)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 689, in http_error_401
errcode, errmsg, headers)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 386, in http_error_default
raise IOError, ('http error', errcode, errmsg, headers)
IOError: ('http error', 401, 'Unauthorized', <httplib.HTTPMessage instance at 0x10764a878>)
I think the solution is here https://openweathermap.org/faq#error401
You need API Key and also you can patch the script:
--- weathercli-2.3.1/weathercli.py.orig 2018-05-10 21:10:41.241120364 +0200
+++ weathercli-2.3.1/weathercli.py 2018-05-10 21:11:25.182121384 +0200
@@ -45,11 +45,11 @@
self.formatter = formatter
def now(self, query, units='imperial'):
- raw_data = urllib.urlopen('http://api.openweathermap.org/data/2.5/weather?q={0}&units={1}'.format(
+ raw_data = urllib.urlopen('http://api.openweathermap.org/data/2.5/weather?q={0}&units={1}&appid=your_api_key_here'.format(
urllib.quote_plus(query),
units
)).read()
-
+
try:
weather = json.loads(raw_data)
except ValueError:
@@ -117,7 +117,7 @@
(60, 'blue'),
(80, 'yellow')
]
-
+
temperature_re = re.compile('(?P<temperature>-?\d+)')
match = temperature_re.search(conditions)
if match:
@@ -126,7 +126,7 @@
return color[1]
return 'red'
return 'white'
-
+
class Weather(object):