File tree 1 file changed +12
-7
lines changed 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change 1
1
import json
2
+ from urllib .error import HTTPError
2
3
from urllib .request import urlopen
3
4
4
5
from errbot import BotPlugin , botcmd
14
15
15
16
16
17
class Coderwall (BotPlugin ):
17
-
18
18
@botcmd
19
19
def coderwall (self , mess , args ):
20
20
"""Shows the badges of a coderwall user
21
21
Example: !coderwall gbin
22
22
"""
23
23
if not args :
24
24
return "Am I supposed to guess the username?..."
25
- args = args .strip ()
26
- content = urlopen ("http://coderwall.com/%s.json" % args )
27
- results = json .loads (content .read ().decode ())
28
- for badge in results ["badges" ]:
29
- self .send (mess .frm , BADGE % badge )
30
- return USER % results
25
+ response = None
26
+ username = args .strip ()
27
+ try :
28
+ content = urlopen (f"http://coderwall.com/{ username } .json" )
29
+ results = json .loads (content .read ().decode ())
30
+ for badge in results ["badges" ]:
31
+ self .send (mess .frm , BADGE % badge )
32
+ response = USER % results
33
+ except HTTPError :
34
+ response = "User not found."
35
+ return response
You can’t perform that action at this time.
0 commit comments