mirror of https://github.com/Mikaela/Limnoria.git
Slight code cleanup and catching of timed out connections.
This commit is contained in:
parent
8f6adf62f5
commit
1879f0786d
|
@ -104,27 +104,35 @@ totalTime = 0
|
||||||
last24hours = structures.queue()
|
last24hours = structures.queue()
|
||||||
|
|
||||||
def search(*args, **kwargs):
|
def search(*args, **kwargs):
|
||||||
global totalSearches, totalTime, last24hours
|
try:
|
||||||
data = google.doGoogleSearch(*args, **kwargs)
|
global totalSearches, totalTime, last24hours
|
||||||
now = time.time()
|
data = google.doGoogleSearch(*args, **kwargs)
|
||||||
totalSearches += 1
|
now = time.time()
|
||||||
totalTime += data.meta.searchTime
|
totalSearches += 1
|
||||||
last24hours.enqueue(now)
|
totalTime += data.meta.searchTime
|
||||||
while last24hours and now - last24hours.peek() > 86400:
|
last24hours.enqueue(now)
|
||||||
last24hours.dequeue()
|
while last24hours and now - last24hours.peek() > 86400:
|
||||||
return data
|
last24hours.dequeue()
|
||||||
|
return data
|
||||||
|
except socket.error, e:
|
||||||
|
if e.args[0] == 110:
|
||||||
|
return 'Connection timed out to Google.com.'
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
class Google(callbacks.PrivmsgCommandAndRegexp):
|
class Google(callbacks.PrivmsgCommandAndRegexp):
|
||||||
threaded = True
|
threaded = True
|
||||||
regexps = sets.Set(['googleSnarfer', 'googleGroups'])
|
regexps = sets.Set(['googleSnarfer', 'googleGroups'])
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
super(self.__class__, self).__init__()
|
||||||
self.total = 0
|
self.total = 0
|
||||||
self.totalTime = 0
|
self.totalTime = 0
|
||||||
self.snarfer = True
|
self.snarfer = True
|
||||||
self.last24hours = structures.queue()
|
self.last24hours = structures.queue()
|
||||||
|
|
||||||
def formatData(self, data):
|
def formatData(self, data):
|
||||||
|
if isinstance(data, basestring):
|
||||||
|
return data
|
||||||
time = 'Search took %s seconds: ' % data.meta.searchTime
|
time = 'Search took %s seconds: ' % data.meta.searchTime
|
||||||
results = []
|
results = []
|
||||||
for result in data.results:
|
for result in data.results:
|
||||||
|
|
Loading…
Reference in New Issue