except IOError: # if the connection times out. This blocks. :(
bot.automsg(public,nick,"The web's broken. Waah!")
+# Look up a currency conversion via xe.com
+def currencyq(bot, cmd, nick, conn, public):
+ args = ' '.join(cmd.split()[1:]).split(' as ')
+ if len(args) != 2 or len(args[0]) != 3 or len(args[1]) != 3:
+ conn.notice(nick, "syntax: currency arg1 as arg2")
+ return
+ targ = ("http://www.xe.com/ucc/convert.cgi?From=%s&To=%s" % (args[0], args[1]))
+ try:
+ currencypage = urllib.urlopen(targ).read()
+ match = re.search(r"(1 %s = [\d\.]+ %s)" % (args[0],args[1]),currencypage,re.MULTILINE)
+ if match == None:
+ bot.automsg(public,nick,"Dear Chief Secretary, there is no money.")
+ else:
+ conversion = match.group(1);
+ conversion = conversion.replace(' ',' ');
+ bot.automsg(public,nick,conversion + " (from xe.com)")
+ except IOError: # if the connection times out. This blocks. :(
+ bot.automsg(public,nick,"The web's broken. Waah!")
+
+
### say to msg/channel
def sayq(bot, cmd, nick, conn, public):
if irc_lower(nick) == irc_lower(bot.owner):