[Frugalware-darcs] vmexam: python/irssi/*: initial import

VMiklos vmiklos at frugalware.org
Thu Jun 21 14:39:41 CEST 2007


Darcsweb-Url: http://darcs.frugalware.org/darcsweb/darcsweb.cgi?r=vmexam;a=darcs_commitdiff;h=20070621123916-e2957-3fe2b65a0d8192a8554d34983eb374abe7a373aa.gz;

[python/irssi/*: initial import
VMiklos <vmiklos at frugalware.org>**20070621123916] {
adddir ./python/irssi
addfile ./python/irssi/hex2ip.py
addfile ./python/irssi/lastfm.py
addfile ./python/irssi/spell.py
addfile ./python/irssi/sztakidict.py
hunk ./python/hex2ip.py 1
-import socket, sys
-
-def hex2ip(s):
-	return ".".join(["%d"%int(n, 16) for n in (s[0:2],s[2:4],s[4:6],s[6:8])])
-try:
-	host = socket.gethostbyaddr(hex2ip(sys.argv[1]))
-except socket.error, str:
-	print str[1]
-	sys.exit(-1)
-print host[0]
rmfile ./python/hex2ip.py
hunk ./python/irssi/hex2ip.py 1
+import irssi, socket
+
+"""hex2ip converter
+type /py load hex2ip to load it
+usage:
+	/hex2ip aabbccdd"""
+
+__author__ = "Miklos Vajna <vmiklos at frugalware.org>"
+__version__ = "0.1"
+__date__ = "Thu, 21 Jun 2007 14:00:00 +0200"
+__copyright__ = "Copyright (c) 2007 Miklos Vajna"
+__license__ = "GPL"
+
+def hex2ip(s):
+	return ".".join(["%d"%int(n, 16) for n in (s[0:2],s[2:4],s[4:6],s[6:8])])
+
+def cmd_hex2ip(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(' ')
+	try:
+		host = socket.gethostbyaddr(hex2ip(argv[0]))
+	except socket.error, str:
+		print str[1]
+		return
+	print host[0]
+
+irssi.command_bind('hex2ip', cmd_hex2ip)
hunk ./python/irssi/lastfm.py 1
+import irssi, urllib
+from xml.dom import minidom
+
+"""interface to last.fm
+type /py load lastfm to use it"""
+
+__author__ = "Miklos Vajna <vmiklos at frugalware.org>"
+__version__ = "0.1"
+__date__ = "Thu, 21 Jun 2007 04:42:58 +0200"
+__copyright__ = "Copyright (c) 2007 Miklos Vajna"
+__license__ = "GPL"
+
+def rec(match):
+	return(chr(string.atoi(match.group()[2:-1])))
+
+def cmd_lastfm(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"""
+	sock = urllib.urlopen("http://ws.audioscrobbler.com/1.0/user/EDITME/recenttracks.xml")
+	xmldoc = minidom.parseString(sock.read())
+	artist = xmldoc.getElementsByTagName('artist')[0].firstChild.toxml().encode("latin2")
+	name = xmldoc.getElementsByTagName('name')[0].firstChild.toxml().encode("latin2")
+	witem.command("/action %s is now playing %s - %s" % (witem.name, artist, name))
+
+irssi.command_bind('lastfm', cmd_lastfm)
hunk ./python/irssi/spell.py 1
+import irssi, re, string, sys, urllib, popen2
+
+"""interface to aspell
+type /py load spell to load it
+type /spell word to use it
+you can define the spelling language on a server and on a channel basis. the
+second takes precedence
+"""
+
+__author__ = "Miklos Vajna <vmiklos at frugalware.org>"
+__version__ = "0.1"
+__date__ = "Thu, 21 Jun 2007 13:51:23 +0200"
+__copyright__ = "Copyright (c) 2007 Miklos Vajna"
+__license__ = "GPL"
+
+server_langs = {
+		'freenode': 'en'
+		}
+channel_langs = {
+		'#frugalware.hu': 'hu'
+		}
+
+def cmd_spell(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(' ')
+
+	if len(argv) > 2:
+		lang = argv[0]
+		word = argv[1]
+	else:
+		lang = "en"
+		if server.tag in server_langs.keys():
+			lang = server_langs[server.tag]
+		if witem:
+			if witem.name in channel_langs.keys():
+				lang = channel_langs[witem.name]
+		word = argv[0]
+	
+	pout, pin = popen2.popen2('aspell -a -l %s' % lang)
+	pin.write("%s\n" % word)
+	pin.close()
+	ret = pout.readlines()
+	pout.close()
+	if ret[1].startswith("*"):
+		print "OK"
+	else:
+		print unicode(ret[1].split(":")[1].strip(), "latin2")
+
+irssi.command_bind('spell', cmd_spell)
hunk ./python/irssi/sztakidict.py 1
+import irssi, re, string, sys, urllib
+
+"""interface to dict.sztaki.hu
+type /py load sztakidict to load it
+usage:
+	/dict lang word
+or
+	/dict word (defaults to en)"""
+
+__author__ = "Miklos Vajna <vmiklos at frugalware.org>"
+__version__ = "0.1"
+__date__ = "Thu, 21 Jun 2007 03:28:51 +0200"
+__copyright__ = "Copyright (c) 2007 Miklos Vajna"
+__license__ = "GPL"
+
+def rec(match):
+	return(chr(string.atoi(match.group()[2:-1])))
+
+def cmd_dict(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(' ')
+	raw = []
+
+	if len(argv) > 2:
+		lang = argv[0]
+		word = argv[1]
+	else:
+		lang = "en"
+		word = argv[0]
+
+	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
+		return
+	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(unicode(re.sub(r'\&\#([0-9]+);', rec, i), "latin2"))
+		print
+	else:
+		print "not found"
+	socket.close()
+
+irssi.command_bind('dict', cmd_dict)
}


More information about the Frugalware-darcs mailing list