File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
zulip_bots/zulip_bots/bots/weather Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 1
1
# See readme.md for instructions on running this code.
2
2
import requests
3
3
import json
4
+ import logging
4
5
5
6
from typing import Any , Dict
6
7
7
8
class WeatherHandler (object ):
8
9
def initialize (self , bot_handler : Any ) -> None :
9
10
self .api_key = bot_handler .get_config_info ('weather' )['key' ]
10
11
self .response_pattern = 'Weather in {}, {}:\n {:.2f} F / {:.2f} C\n {}'
12
+ self .check_api_key ()
13
+
14
+ def check_api_key (self ) -> None :
15
+ url = 'http://api.openweathermap.org/data/2.5/weather?q=nyc&APPID=' + self .api_key
16
+ test_response = requests .get (url )
17
+ try :
18
+ test_response_data = test_response .json ()
19
+ if test_response_data ['cod' ] == 401 :
20
+ logging .error ('API Key not valid. Please see doc.md to find out how to get it.' )
21
+ except KeyError :
22
+ pass
11
23
12
24
def usage (self ) -> str :
13
25
return '''
You can’t perform that action at this time.
0 commit comments