Skip to content

Commit 1812d5c

Browse files
committed
Hey look at this cool new function in Python 3.4
1 parent 49bd51f commit 1812d5c

1 file changed

Lines changed: 11 additions & 19 deletions

File tree

plugins/whois.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
1+
from contextlib import suppress
2+
13
import pythonwhois
24

35
from cloudbot import hook
46

57

68
@hook.command
79
def 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 = "\x02Registrar\x02: {}".format(data["registrar"][0])
16-
info.append(i)
17-
except Exception as e:
18-
print(e)
19-
pass
20-
21-
try:
22-
i = "\x02Registered\x02: {}".format(data["creation_date"][0].strftime("%d-%m-%Y"))
23-
info.append(i)
24-
except Exception:
25-
pass
26-
27-
try:
28-
i = "\x02Expires\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("\x02Registrar\x02: {}".format(data["registrar"][0]))
18+
19+
with suppress(KeyError):
20+
info.append("\x02Registered\x02: {}".format(data["creation_date"][0].strftime("%d-%m-%Y")))
21+
22+
with suppress(KeyError):
23+
info.append("\x02Expires\x02: {}".format(data["expiration_date"][0].strftime("%d-%m-%Y")))
3224

3325
info_text = ", ".join(info)
3426
return "{} - {}".format(domain, info_text)

0 commit comments

Comments
 (0)