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.add_timer(self.ping_interval,
self.send_ping) 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): def cmd_privmsg(self, sender, forum, addl):
infobot.InfoBot.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 f = forum.notice
else: else:
f = forum.msg f = forum.msg
return True
f('http://%s:%d/%d' % (URLSERVER[0], URLSERVER[1], idx)) 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])"), bindings.append((re.compile(r".*\b(?P<url>\b[a-z]+://[-a-z0-9_=!?#$@~%&*+/:;.,\w]+[-a-z0-9_=#$@~%&*+/\w])"),
shorturl)) 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): def cdecl(self, sender, forum, addl, match):
jibberish = match.group('jibberish') jibberish = match.group('jibberish')
o, i = os.popen2('/usr/bin/cdecl') o, i = os.popen2('/usr/bin/cdecl')
@ -325,9 +327,9 @@ class FireBot(infobot.InfoBot, procbot.ProcBot):
d) d)
symbol = match.group('symbol') 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) cb)
bindings.append((re.compile(r"^quote +(?P<symbol>[.a-zA-Z]+)$"), bindings.append((re.compile(r"^quote +(?P<symbol>[-.a-zA-Z]+)$"),
quote)) quote))
def currency(self, sender, forum, addl, match): 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') % forum.msg(('%0.4f %s = %0.4f %s') %
(amt, frm, ans, to)) (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)), (frm, to)),
cb) cb)
bindings.append((re.compile(r"^how much is (?P<amt>[0-9.]+) ?(?P<from>[A-Z]{3}) in (?P<to>[A-Z]{3})\??$"), 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: else:
amt = -1 amt = -1
self.whuffie_mod(nick, amt) 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)) whuffie_modify))
msg_cat['whuffie whore'] = ("Nothing happens.", msg_cat['whuffie whore'] = ("Nothing happens.",
'A hollow voice says, "Fool."') 'A hollow voice says, "Fool."')

View File

@ -65,14 +65,34 @@ class Gallium(firebot.FireBot, ProcBot):
bindings.append((re.compile(r"^u\+rand$"), bindings.append((re.compile(r"^u\+rand$"),
randglyph)) 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) bindings.extend(firebot.FireBot.bindings)
class Wiibot(Gallium): class Wiibot(Gallium):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
Gallium.__init__(self, *args, **kwargs) Gallium.__init__(self, *args, **kwargs)
self.wiis = [] self.wiis = []
self.add_timer(27, self.check_wiis) self.add_timer(30, self.check_wiis)
def check_wiis(self): def check_wiis(self):
d = feedparser.parse('http://www.wiitracker.com/rss.xml') d = feedparser.parse('http://www.wiitracker.com/rss.xml')
@ -81,6 +101,11 @@ class Wiibot(Gallium):
for e in d.entries: for e in d.entries:
t = e.title t = e.title
if 'no stock at this time' not in t: if 'no stock at this time' not in t:
try:
price = int(t[-3:])
except:
price = 1
if price < 450:
nt.append(t) nt.append(t)
if self.wiis != nt: if self.wiis != nt:
if nt: if nt:
@ -92,7 +117,7 @@ class Wiibot(Gallium):
except: except:
pass pass
self.add_timer(27, self.check_wiis) self.add_timer(23, self.check_wiis)
if __name__ == '__main__': if __name__ == '__main__':
@ -116,7 +141,7 @@ if __name__ == '__main__':
us.getsockname()[1]) us.getsockname()[1])
# gallium # gallium
gallium = Wiibot(('localhost', 6667), gallium = Gallium(('localhost', 6667),
['gallium'], ['gallium'],
"I'm a little printf, short and stdout", "I'm a little printf, short and stdout",
["#woozle", "#gallium"]) ["#woozle", "#gallium"])

View File

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