[Otfbot-svn] r130 - in trunk: . modules

cato- at BerliOS cato-
Sa Jun 30 01:01:39 CEST 2007


Author: cato-
Date: 2007-06-30 01:01:30 +0200 (Sat, 30 Jun 2007)
New Revision: 130

Modified:
   trunk/modules/kursMod.py
   trunk/otfbot.py
Log:
* updated kursMod for using the commands-callback

Modified: trunk/modules/kursMod.py
===================================================================
--- trunk/modules/kursMod.py	2007-06-29 12:05:58 UTC (rev 129)
+++ trunk/modules/kursMod.py	2007-06-29 23:01:30 UTC (rev 130)
@@ -35,57 +35,58 @@
 	def joined(self, channel):
 		self.channels[channel]=1
 	
-	def msg(self, user, channel, msg):
+	def command(self, user, channel, command, options):
 		nick=user.split("!")[0]
-		if msg.split(" ")[0][1:] in self.commands and 0 < (time.time() - self.time) < 5:
+		if command in self.commands and 0 < (time.time() - self.time) < 5:
 			self.bot.sendmsg(channel,"Wait a minute ...")
-		else:
-			self.time = time.time()
-			if msg[:5] == "!kurs":
-				datas = urllib.urlopen("http://de.old.finance.yahoo.com/d/quotes.csv?s="+urllib.quote_plus(" ".join(msg.split(" ")[1:]))+"&f=nsl1d1t1cohgvc4x&e=.csv").read().strip().split('\r\n')
-				if len(datas) > 4:
-					datas = datas[:3]
-				for data in datas:
-					data = data.strip().split(";")
-					date = data[3].split("/")
-					d = { 'name' : data[0], 
-					      'symbol' : data[1],
-					      'kurs' : data[2],
-					      'day' : date[1]+"."+date[0]+"."+date[2],
-					      'time' : data[4],
-					      'change_kurs' : data[5].split(" - ")[0],
-					      'change_percent' : data[5].split(" - ")[1],
-					      'last_day' : data[6],
-					      'top_range' : data[7],
-					      'low_range' : data[8],
-					      'volumen' : data[9],
-					      'currency' : data[10],
-					      'boerse' : data[11]
-					}
-					# \x03C C=Colorcode
-					answer = d['day']+", "+d['time']+" "+ d['name']+" ("+d['boerse']+":"+d['symbol']+") "+d['kurs']+" "+d['currency']
-					if d['change_kurs'] != "N/A":
-						if d['change_kurs'][:1] == "+":
-							color="\x033"
-						elif d['change_kurs'][:1] == "-":
-							color="\x034"
-						else:
-							color=""
-						answer = answer +", "+color+d['change_kurs']+" "+d['currency']+"\x03, "+color+d['change_percent']+"\x03, Vol.:"+d['volumen']+" St."
-					if d['low_range'] != "N/A":
-						answer = answer + ", Intraday "+d['low_range']+ " bis "+d['top_range']+" "+d['currency']+"."
-					if d['kurs'] == "N/A":
-						answer = "Der geforderte Kurs wurde nicht gefunden."
-					self.bot.sendmsg(channel,answer)
-			if msg[:4] == "!wkn":
-				res=[]
-				for line in urllib.urlopen("http://de.finsearch.yahoo.com/de/index.php?s=de_sort&nm="+urllib.quote_plus(" ".join(msg.split(" ")[1:]))+"&tp=S").read().split("\n"):
-					if line[:3] == " <a":
-						res.append(re.sub('.*s\=([^"]*)">([^<]*)<.*',r'\1;\2',line).split(";"))
-				if len(res) < 4:
-					to = len(res)
-				else:
-					to = 4
-				for i in range(to):
-					self.bot.sendmsg(channel,res[i][0]+"\t"+res[i][1])
-
+			return
+		self.time = time.time()
+		if command == "kurs":
+			datas = urllib.urlopen("http://de.old.finance.yahoo.com/d/quotes.csv?s="+urllib.quote_plus(options)+"&f=nsl1d1t1cohgvc4x&e=.csv").read().strip().split('\r\n')
+			print datas
+			if len(datas) > 4:
+				datas = datas[:3]
+			for data in datas:
+				data = data.strip().split(";")
+				print data
+				date = data[4].split("/")
+				d = { 'name' : data[0], 
+				      'symbol' : data[1],
+				      'kurs' : data[2],
+				      'day' : date[1]+"."+date[0]+"."+date[2],
+				      'time' : data[3],
+				      'change_kurs' : "", #data[5].split(" - ")[0],
+				      'change_percent' : data[5], #.split(" - ")[1],
+				      'last_day' : data[6],
+				      'top_range' : data[7],
+				      'low_range' : data[8],
+				      'volumen' : data[9],
+				      'currency' : data[10],
+				      'boerse' : data[11]
+				}
+				# \x03C C=Colorcode
+				answer = d['day']+", "+d['time']+" "+ d['name']+" ("+d['boerse']+":"+d['symbol']+") "+d['kurs']+" "+d['currency']
+				if d['change_kurs'] != "N/A":
+					if d['change_kurs'][:1] == "+":
+						color="\x033"
+					elif d['change_kurs'][:1] == "-":
+						color="\x034"
+					else:
+						color=""
+					answer = answer +", "+color+d['change_kurs']+" "+d['currency']+"\x03, "+color+d['change_percent']+"\x03, Vol.:"+d['volumen']+" St."
+				if d['low_range'] != "N/A":
+					answer = answer + ", Intraday "+d['low_range']+ " bis "+d['top_range']+" "+d['currency']+"."
+				if d['kurs'] == "N/A":
+					answer = "Der geforderte Kurs wurde nicht gefunden."
+				self.bot.sendmsg(channel,answer)
+		if command == "wkn":
+			res=[]
+			for line in urllib.urlopen("http://de.finsearch.yahoo.com/de/index.php?s=de_sort&nm="+urllib.quote_plus(options)+"&tp=S").read().split("\n"):
+				if line[:3] == " <a":
+					res.append(re.sub('.*s\=([^"]*)">([^<]*)<.*',r'\1;\2',line).split(";"))
+			if len(res) < 4:
+				to = len(res)
+			else:
+				to = 4
+			for i in range(to):
+				self.bot.sendmsg(channel,res[i][0]+"\t"+res[i][1])
\ No newline at end of file

Modified: trunk/otfbot.py
===================================================================
--- trunk/otfbot.py	2007-06-29 12:05:58 UTC (rev 129)
+++ trunk/otfbot.py	2007-06-29 23:01:30 UTC (rev 130)
@@ -430,7 +430,7 @@
 		@param user: the user, which issues the command
 		@type user: string
 		@param channel: the channel to which the message was sent or my nickname if it was a private message
-		@tpye channel: string
+		@type channel: string
 		@param command: the !command without the !
 		@type command: string
 		@param options: eventual options specified after !command (e.g. "!command foo")




Mehr Informationen über die Mailingliste Otfbot-dev