From: Matthew Vernon Date: Mon, 1 Aug 2011 11:26:35 +0000 (+0100) Subject: currency command, written by Owen Dunn X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~matthewv/git?a=commitdiff_plain;h=868ccbe2f35203adfc0eaf7b743f18c6397e0b93;p=irc.git currency command, written by Owen Dunn --- diff --git a/Servus-chiark.py b/Servus-chiark.py index 81f8076..e0eb741 100644 --- a/Servus-chiark.py +++ b/Servus-chiark.py @@ -169,6 +169,7 @@ commands = {"karma": (c.karmaq,karmadb), "nsfw": (c.nsfwq,urldb), "nws": (c.nsfwq,urldb), "units": c.unitq, + "currency":c.currencyq, "help": c.helpq, "say": c.sayq, "do": c.doq, diff --git a/commands.py b/commands.py index d22655e..882b67a 100644 --- a/commands.py +++ b/commands.py @@ -242,6 +242,26 @@ def defineq(bot, cmd, nick, conn, public): 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):