[Frugalware-darcs] vmexam: python/irssi/whois.py: new script

VMiklos vmiklos at frugalware.org
Thu Jun 21 16:05:11 CEST 2007


Darcsweb-Url: http://darcs.frugalware.org/darcsweb/darcsweb.cgi?r=vmexam;a=darcs_commitdiff;h=20070621140445-e2957-8fc86d01285c83e1c4b3f13697b58fc112e3d3f3.gz;

[python/irssi/whois.py: new script
VMiklos <vmiklos at frugalware.org>**20070621140445] {
hunk ./python/dict.py 1
-#!/usr/bin/env python
-
-# sztaki szotar cmdline interface
-# don't use it or i'll be killed ;-)
-
-import re, string, sys, urllib
-
-def rec(match):
-	return(chr(string.atoi(match.group()[2:-1])))
-
-raw = []
-
-if len(sys.argv) > 2:
-	lang = sys.argv[1]
-	word = sys.argv[2]
-else:
-	lang = "en"
-	word = sys.argv[1]
-
-if lang == "hu":
-	url = "http://szotar.sztaki.hu/dict_search.php?S=W&L=HUN%3AENG%3AEngHunDict&W=" + word
-else:
-	url = "http://szotar.sztaki.hu/dict_search.php?S=W&W=" + word
-
-try:
-	socket = urllib.urlopen(url)
-except IOError, str:
-	print "problem: %s" % str
-	sys.exit()
-while True:
-	line = socket.readline()
-	if not line:
-		break
-	if line.find("nbsp") > 0:
-		raw.append(re.sub(r'.*&nbsp;(.*)<br/>\n', r'\1', line))
-if len(raw):
-	first = True
-	for i in raw:
-		if first:
-			first = False
-		else:
-			sys.stdout.write(", ")
-		sys.stdout.write(re.sub(r'\&\#([0-9]+);', rec, i))
-	print
-else:
-	print "not found"
-socket.close()
rmfile ./python/dict.py
addfile ./python/irssi/whois.py
hunk ./python/whois.py 1
-import urllib, sys
-
-sock = urllib.urlopen("http://www.completewhois.com/cgi2/whois.cgi?query=%s" % sys.argv[1])
-for i in sock.readlines():
-	if i.startswith("descr: "):
-		print i.strip()
-		break
rmfile ./python/whois.py
hunk ./python/irssi/whois.py 1
+import irssi, urllib, socket
+
+"""interface to completewhois.com
+type /py load whois to load it
+usage:
+	/pywhois hostname
+or
+	/pywhois ip
+
+it will tell you the first description line (usually the name of the network
+provider) and the country code (useful when no reverse dns is available)"""
+
+__author__ = "Miklos Vajna <vmiklos at frugalware.org>"
+__version__ = "0.1"
+__date__ = "Thu, 21 Jun 2007 16:00:38 +0200"
+__copyright__ = "Copyright (c) 2007 Miklos Vajna"
+__license__ = "GPL"
+
+def cmd_whois(data, server, witem):
+	"""data - contains the parameters for /dict
+server - the active server in window
+witem - the active window item (eg. channel, query)
+        or None if the window is empty"""
+
+	argv = data.split(' ')
+
+	# get the ip if this is a hostname
+	ip = argv[0]
+
+	try:
+		socket.inet_aton(ip)
+	except socket.error:
+		ip = socket.gethostbyname(ip)
+
+	sock = urllib.urlopen("http://www.completewhois.com/cgi2/whois.cgi?query=%s" % ip)
+	descr = None
+	country = None
+	for i in sock.readlines():
+		if i.startswith("descr: "):
+			if not descr:
+				descr = i.split(":")[1].strip()
+		if i.startswith("country: "):
+			if not country:
+				country = i.split(":")[1].strip()
+	sock.close()
+	print "%s, %s" % (descr, country)
+
+irssi.command_bind('pywhois', cmd_whois)
}


More information about the Frugalware-darcs mailing list