mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-27 21:22:39 +01:00
Money is a float not an int. Also, uber simplify Currency.yahoo since they
provide a csv file. Yay, no html parsing!
This commit is contained in:
parent
eb23fa3b14
commit
eb60864c51
@ -85,7 +85,7 @@ class Currency(callbacks.Privmsg):
|
||||
(number, curr1, curr2) = privmsgs.getArgs(args, required=2,
|
||||
optional=1)
|
||||
try:
|
||||
number = int(number)
|
||||
number = float(number)
|
||||
except ValueError:
|
||||
curr2 = curr1
|
||||
curr1 = number
|
||||
@ -120,10 +120,6 @@ class Currency(callbacks.Privmsg):
|
||||
irc.error('XE must\'ve changed the format of their site.')
|
||||
return
|
||||
|
||||
_yahooConvert = re.compile(r'\w{6}=X</a></td><td class[^>]+><b>([\d.]+)'
|
||||
r'</b></td><td class[^>]+>\w{3} \d\d?</td><td'
|
||||
r' class=[^>]+>[\d.]+</td><td class[^>]+><b>'
|
||||
r'([\d,]+(?:.0{2}))', re.I | re.S)
|
||||
def yahoo(self, irc, msg, args):
|
||||
"""[<number>] <currency1> to <currency2>
|
||||
|
||||
@ -133,39 +129,34 @@ class Currency(callbacks.Privmsg):
|
||||
(number, curr1, curr2) = privmsgs.getArgs(args, required=2,
|
||||
optional=1)
|
||||
try:
|
||||
number = int(number)
|
||||
number = float(number)
|
||||
except ValueError:
|
||||
curr2 = curr1
|
||||
curr1 = number
|
||||
number = 1
|
||||
curr1 = curr1.lower()
|
||||
curr2 = curr2.lower()
|
||||
if curr2.startswith('to '):
|
||||
curr1 = curr1.upper()
|
||||
curr2 = curr2.upper()
|
||||
if curr2.startswith('TO '):
|
||||
curr2 = curr2[3:]
|
||||
if len(curr1) != 3 and len(curr2) != 3:
|
||||
irc.error(self._symbolError)
|
||||
return
|
||||
url = 'http://finance.yahoo.com/currency/convert?amt=%s&from=%s&'\
|
||||
'to=%s&submit=Convert'
|
||||
url = r'http://finance.yahoo.com/d/quotes.csv?'\
|
||||
r's=%s%s=X&f=sl1d1t1ba&e=.csv' % (curr1, curr2)
|
||||
try:
|
||||
text = webutils.getUrl(url % (number, curr1, curr2))
|
||||
text = webutils.getUrl(url)
|
||||
except webutils.WebError, e:
|
||||
irc.error(str(e))
|
||||
return
|
||||
conv = self._yahooConvert.search(text)
|
||||
if conv is not None:
|
||||
resp = [conv.group(1), curr1.upper(), '=',
|
||||
conv.group(2).replace(',', ''), curr2.upper()]
|
||||
if '.' not in resp[0]:
|
||||
resp[0] = '%s.00' % resp[0]
|
||||
elif resp[0].endswith('.0'):
|
||||
resp[0] = '%.00' % resp[:-2]
|
||||
irc.reply(' '.join(resp))
|
||||
return
|
||||
else:
|
||||
irc.error('Either you used the wrong currency symbol(s) or Yahoo '
|
||||
'changed the format of their site.')
|
||||
if 'N/A' in text:
|
||||
irc.error('You used an incorrect currency symbol.')
|
||||
return
|
||||
conv = text.split(',')[1]
|
||||
conv = number * float(conv)
|
||||
resp = [str(number), curr1.upper(), '=', str(conv), curr2.upper()]
|
||||
if '.' not in resp[0] and 'e' not in resp[0]:
|
||||
resp[0] = '%s.00' % resp[0]
|
||||
irc.reply(' '.join(resp))
|
||||
|
||||
conf.registerPlugin('Currency')
|
||||
conf.registerChannelValue(conf.supybot.plugins.Currency, 'command',
|
||||
|
Loading…
Reference in New Issue
Block a user