Fix things that use Yahoo!

This commit is contained in:
Neale Pickett 2008-03-27 17:01:51 -06:00
parent 5d26919667
commit c437491347
3 changed files with 58 additions and 29 deletions

View File

@ -69,19 +69,6 @@ class FireBot(infobot.InfoBot, procbot.ProcBot):
self.add_timer(self.ping_interval,
self.send_ping)
def note(self, sender, forum, addl, match):
whom = match.group('whom')
what = match.group('what')
when = time.time()
note = "%f:%s:%s" % (when, sender.name(), what)
n = self.getall(whom, special="note")
n.append(note)
self.set(whom, n, special="note")
forum.msg(self.gettext('okay', sender=sender.name()))
bindings.append((re.compile(r"^\008[:, ]+note (to )?(?P<whom>[^: ]+):? +(?P<what>.*)"),
note))
bindings.append((re.compile(r"^\008[:, ]+later tell (?P<whom>[^: ]+):? +(?P<what>.*)"),
note))
def cmd_privmsg(self, sender, forum, addl):
infobot.InfoBot.cmd_privmsg(self, sender, forum, addl)
@ -168,10 +155,25 @@ class FireBot(infobot.InfoBot, procbot.ProcBot):
f = forum.notice
else:
f = forum.msg
return True
f('http://%s:%d/%d' % (URLSERVER[0], URLSERVER[1], idx))
bindings.append((re.compile(r".*\b(?P<url>\b[a-z]+://[-a-z0-9_=!?#$@~%&*+/:;.,\w]+[-a-z0-9_=#$@~%&*+/\w])"),
shorturl))
def note(self, sender, forum, addl, match):
whom = match.group('whom')
what = match.group('what')
when = time.time()
note = "%f:%s:%s" % (when, sender.name(), what)
n = self.getall(whom, special="note")
n.append(note)
self.set(whom, n, special="note")
forum.msg(self.gettext('okay', sender=sender.name()))
bindings.append((re.compile(r"^\008[:, ]+note (to )?(?P<whom>[^: ]+):? +(?P<what>.*)"),
note))
bindings.append((re.compile(r"^\008[:, ]+later tell (?P<whom>[^: ]+):? +(?P<what>.*)"),
note))
def cdecl(self, sender, forum, addl, match):
jibberish = match.group('jibberish')
o, i = os.popen2('/usr/bin/cdecl')
@ -325,9 +327,9 @@ class FireBot(infobot.InfoBot, procbot.ProcBot):
d)
symbol = match.group('symbol')
WebRetriever('http://quote.yahoo.com/d/quotes.csv?s=%s&f=sl1d1t1c1ohgvj1pp2owern&e=.csv' % symbol,
WebRetriever('http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=sl1d1t1c1ohgvj1pp2owern&e=.csv' % symbol,
cb)
bindings.append((re.compile(r"^quote +(?P<symbol>[.a-zA-Z]+)$"),
bindings.append((re.compile(r"^quote +(?P<symbol>[-.a-zA-Z]+)$"),
quote))
def currency(self, sender, forum, addl, match):
@ -352,7 +354,7 @@ class FireBot(infobot.InfoBot, procbot.ProcBot):
forum.msg(('%0.4f %s = %0.4f %s') %
(amt, frm, ans, to))
WebRetriever(('http://quote.yahoo.com/d/quotes.csv?s=%s%s%%3DX&f=sl1d1t1c1ohgvj1pp2owern&e=.csv' %
WebRetriever(('http://download.finance.yahoo.com/d/quotes.csv?s=%s%s%%3DX&f=sl1d1t1c1ohgvj1pp2owern&e=.csv' %
(frm, to)),
cb)
bindings.append((re.compile(r"^how much is (?P<amt>[0-9.]+) ?(?P<from>[A-Z]{3}) in (?P<to>[A-Z]{3})\??$"),
@ -377,7 +379,7 @@ class FireBot(infobot.InfoBot, procbot.ProcBot):
else:
amt = -1
self.whuffie_mod(nick, amt)
bindings.append((re.compile(r"^(?P<nick>\w+)(?P<mod>\+\+|\-\-)[? ]*$"),
bindings.append((re.compile(r"^(?P<nick>[-\w]+)(?P<mod>\+\+|\-\-)[? ]*$"),
whuffie_modify))
msg_cat['whuffie whore'] = ("Nothing happens.",
'A hollow voice says, "Fool."')

View File

@ -65,14 +65,34 @@ class Gallium(firebot.FireBot, ProcBot):
bindings.append((re.compile(r"^u\+rand$"),
randglyph))
def rollthebones(self, sender, forum, addl, match):
what = match.group(0)
howmany = int(match.group(1))
sides = int(match.group(2))
mult = int(match.group(4) or 1)
dice = []
acc = 0
for i in range(howmany):
j = random.randint(1, sides)
dice.append(j)
acc += j
acc *= mult
if howmany > 1:
forum.msg('%s: %d %r' % (what, acc, dice))
else:
forum.msg('%s: %d' % (what, acc))
bindings.append((re.compile(r'\b([1-9][0-9]*)d([1-9][0-9]*)(x([1-9][0-9]*))?\b'),
rollthebones))
bindings.extend(firebot.FireBot.bindings)
class Wiibot(Gallium):
def __init__(self, *args, **kwargs):
Gallium.__init__(self, *args, **kwargs)
self.wiis = []
self.add_timer(27, self.check_wiis)
self.add_timer(30, self.check_wiis)
def check_wiis(self):
d = feedparser.parse('http://www.wiitracker.com/rss.xml')
@ -81,7 +101,12 @@ class Wiibot(Gallium):
for e in d.entries:
t = e.title
if 'no stock at this time' not in t:
nt.append(t)
try:
price = int(t[-3:])
except:
price = 1
if price < 450:
nt.append(t)
if self.wiis != nt:
if nt:
for t in nt:
@ -92,7 +117,7 @@ class Wiibot(Gallium):
except:
pass
self.add_timer(27, self.check_wiis)
self.add_timer(23, self.check_wiis)
if __name__ == '__main__':
@ -116,10 +141,10 @@ if __name__ == '__main__':
us.getsockname()[1])
# gallium
gallium = Wiibot(('localhost', 6667),
['gallium'],
"I'm a little printf, short and stdout",
["#woozle", "#gallium"])
gallium = Gallium(('localhost', 6667),
['gallium'],
"I'm a little printf, short and stdout",
["#woozle", "#gallium"])
gallium.shorturlnotice = False
gallium.debug = debug

View File

@ -169,14 +169,16 @@ class InfoBot(BindingsBot):
bindings.append((re.compile(r"^\008[,: ]+unlock (?P<key>.+)$", re.IGNORECASE),
unlock_entry))
def forget_and_lock(self, sender, forum, addl, match):
def obliterate(self, sender, forum, addl, match):
key = match.group('key')
self.unlock(key)
self.delete(key)
try:
self.delete(key)
except KeyError:
pass
self.lock(key)
forum.msg(self.gettext('okay', key=key, sender=sender.name()))
bindings.append((re.compile(r"^\008[,: ]+forget and lock (?P<key>.+)$", re.IGNORECASE),
forget_and_lock))
bindings.append((re.compile(r"^\008[,: ]+obliterate (?P<key>.+)$", re.IGNORECASE),
obliterate))
# Literal entry
def literal(self, sender, forum, addl, match):