[Frugalware-darcs] vmexam: python/irssi/cia: import

VMiklos vmiklos at frugalware.org
Fri Jun 22 00:25:12 CEST 2007


Darcsweb-Url: http://darcs.frugalware.org/darcsweb/darcsweb.cgi?r=vmexam;a=darcs_commitdiff;h=20070621222455-e2957-5d993e2e5b524614e7cfc387aae8157c61121df4.gz;

[python/irssi/cia: import
VMiklos <vmiklos at frugalware.org>**20070621222455] {
addfile ./python/irssi/cia.py
hunk ./python/irssi/cia.py 1
+import irssi, urllib
+from sgmllib import SGMLParser
+
+"""interface to cia.vc
+type /py load cia to load it
+usage:
+	/cia"""
+
+__author__ = "Miklos Vajna <vmiklos at frugalware.org>"
+__version__ = "0.1"
+__date__ = "Fri, 22 Jun 2007 00:20:02 +0200"
+__copyright__ = "Copyright (c) 2007 Miklos Vajna"
+__license__ = "GPL"
+
+class HTMLParser(SGMLParser):
+	def reset(self):
+		SGMLParser.reset(self)
+		self.inrow = False
+		self.rows = []
+		self.row = []
+
+	def start_div(self, attrs):
+		for k, v in attrs:
+			if k == "class" and v == "row":
+				self.inrow = True
+	
+	def start_td(self, attrs):
+		for k, v in attrs:
+			if k == "class" and v == "j":
+				self.indesc = True
+
+	def end_div(self):
+		if self.inrow:
+			self.rows.append("".join(self.row))
+			self.row = []
+			self.inrow = False
+
+	def handle_data(self, text):
+		if self.inrow:
+			self.row.append(text)
+
+def cmd_cia(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://cia.vc/stats/author/VMiklos%20%3Cvmiklos%40frugalware.org%3E")
+	data = sock.read()
+	sock.close()
+
+	parser = HTMLParser()
+	parser.reset()
+	parser.feed(data)
+	parser.close()
+
+	for i in parser.rows:
+		if "so far today" in i:
+			print i
+
+irssi.command_bind('cia', cmd_cia)
}


More information about the Frugalware-darcs mailing list