mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-17 14:10:41 +01:00
Added a set of deepthoughts so lookup is faster if the queue gets large.
This commit is contained in:
parent
5644c8da57
commit
b64e0d5730
@ -55,6 +55,7 @@ class Http(callbacks.Privmsg):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
callbacks.Privmsg.__init__(self)
|
callbacks.Privmsg.__init__(self)
|
||||||
self.deepthoughtq = structures.queue()
|
self.deepthoughtq = structures.queue()
|
||||||
|
self.deepthoughts = set()
|
||||||
|
|
||||||
def deepthought(self, irc, msg, args):
|
def deepthought(self, irc, msg, args):
|
||||||
"""takes no arguments
|
"""takes no arguments
|
||||||
@ -65,13 +66,15 @@ class Http(callbacks.Privmsg):
|
|||||||
thought = ' ' * 512
|
thought = ' ' * 512
|
||||||
now = time.time()
|
now = time.time()
|
||||||
while self.deepthoughtq and now - self.deepthoughtq[0][0] > 86400:
|
while self.deepthoughtq and now - self.deepthoughtq[0][0] > 86400:
|
||||||
self.deepthoughtq.dequeue()
|
s = self.deepthoughtq.dequeue()
|
||||||
while len(thought) > 450 or thought in self.deepthoughtq:
|
self.deepthoughts.remove(s)
|
||||||
|
while len(thought) > 430 or thought in self.deepthoughts:
|
||||||
fd = urllib2.urlopen(url)
|
fd = urllib2.urlopen(url)
|
||||||
s = fd.read()
|
s = fd.read()
|
||||||
thought = s.split('<br>')[2]
|
thought = s.split('<br>')[2]
|
||||||
thought = ' '.join(thought.split())
|
thought = ' '.join(thought.split())
|
||||||
self.deepthoughtq.enqueue((now, thought))
|
self.deepthoughtq.enqueue((now, thought))
|
||||||
|
self.deepthoughts.add(thought)
|
||||||
irc.reply(msg, thought)
|
irc.reply(msg, thought)
|
||||||
|
|
||||||
_titleRe = re.compile(r'<title>(.*)</title>')
|
_titleRe = re.compile(r'<title>(.*)</title>')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user