File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from contextlib import suppress
2+
13import pythonwhois
24
35from cloudbot import hook
46
57
68@hook .command
79def whois (text ):
10+ """<domain> -- Does a whois query on <domain>."""
811 domain = text .strip ().lower ()
912
1013 data = pythonwhois .get_whois (domain , normalized = True )
11-
1214 info = []
1315
14- try :
15- i = "\x02 Registrar\x02 : {}" .format (data ["registrar" ][0 ])
16- info .append (i )
17- except Exception as e :
18- print (e )
19- pass
20-
21- try :
22- i = "\x02 Registered\x02 : {}" .format (data ["creation_date" ][0 ].strftime ("%d-%m-%Y" ))
23- info .append (i )
24- except Exception :
25- pass
26-
27- try :
28- i = "\x02 Expires\x02 : {}" .format (data ["expiration_date" ][0 ].strftime ("%d-%m-%Y" ))
29- info .append (i )
30- except Exception :
31- pass
16+ with suppress (KeyError ):
17+ info .append ("\x02 Registrar\x02 : {}" .format (data ["registrar" ][0 ]))
18+
19+ with suppress (KeyError ):
20+ info .append ("\x02 Registered\x02 : {}" .format (data ["creation_date" ][0 ].strftime ("%d-%m-%Y" )))
21+
22+ with suppress (KeyError ):
23+ info .append ("\x02 Expires\x02 : {}" .format (data ["expiration_date" ][0 ].strftime ("%d-%m-%Y" )))
3224
3325 info_text = ", " .join (info )
3426 return "{} - {}" .format (domain , info_text )
You can’t perform that action at this time.
0 commit comments