summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsand <daniel@spatof.org>2013-05-13 16:10:50 (GMT)
committer sand <daniel@spatof.org>2013-05-13 16:10:50 (GMT)
commit10fee6f21f45ea358c57918a53ce456daf01f770 (patch)
treeb9d6839023e5f9b1ff21a8eab433c642c1ea57aa
parentf615999c8d9ee0f1ecb01b356204298b9ffe3d6d (diff)
Eztv plugin, tasks
-rw-r--r--pinolo/bot.py7
-rw-r--r--pinolo/plugins/eztv.py (renamed from pinolo/plugins/_eztv.py)28
-rw-r--r--pinolo/tasks.py18
3 files changed, 35 insertions, 18 deletions
diff --git a/pinolo/bot.py b/pinolo/bot.py
index 8638c63..428cdb9 100644
--- a/pinolo/bot.py
+++ b/pinolo/bot.py
@@ -172,13 +172,12 @@ class Bot(SignalDispatcher):
the output to the correct channel or nickname.
"""
try:
- # conn_name, goo = self.coda.get(False, 1)
- conn_name, goo = self.coda.get_nowait()
+ data = list(self.coda.get_nowait())
except Queue.Empty, e:
pass
else:
- for line in goo.split("\n"):
- self.connections[conn_name].msg("#test", line)
+ fn = data.pop(0)
+ fn(*data)
def handle_cron(self):
"""A simple crontab that will be run approximatly every
diff --git a/pinolo/plugins/_eztv.py b/pinolo/plugins/eztv.py
index ac78485..056981a 100644
--- a/pinolo/plugins/_eztv.py
+++ b/pinolo/plugins/eztv.py
@@ -8,15 +8,33 @@
:copyright: (c) 2013 Daniel Kertesz
:license: BSD, see LICENSE for more details.
"""
+import re
import requests
from bs4 import BeautifulSoup
from pinolo.plugins import Plugin
+from pinolo.tasks import Task
+# URL with search form
SEARCH_URL = "http://eztv.it/search/"
+
+# Maximum number of results returned
MAX_RESULTS = 6
+class EztvTask(Task):
+ def run(self):
+ results = search_eztv(self.event.text)
+
+ if not results:
+ self.put_results(self.reply, u"Non ho trovato niente")
+ return
+ else:
+ for result in results[:MAX_RESULTS]:
+ self.put_results(self.event.client.notice,
+ self.event.user.nickname,
+ result)
+
def search_eztv(text):
payload = {
'SearchString1': text
@@ -57,12 +75,6 @@ class EztvPlugin(Plugin):
def on_cmd_eztv_search(self, event):
if not event.text:
return
- results = search_eztv(event.text)
-
- if not results:
- event.reply(u"Non ho trovato una cippa di cazzo, sory")
- return
- for result in results[:MAX_RESULTS]:
- # event.reply(result)
- event.client.notice(event.user.nickname, result)
+ t = EztvTask(event)
+ t.start()
diff --git a/pinolo/tasks.py b/pinolo/tasks.py
index e155689..c58e9e7 100644
--- a/pinolo/tasks.py
+++ b/pinolo/tasks.py
@@ -19,20 +19,26 @@ class Task(threading.Thread):
"""A task is an execution unit that will be run in a separate thread
that should not block tha main thread (handling irc connections).
"""
- def __init__(self, connection_name, queue, *args, **kwargs):
- self.connection_name = connection_name
- self.queue = queue
+ def __init__(self, event, *args, **kwargs):
+ self.event = event
super(Task, self).__init__(*args, **kwargs)
+ @property
+ def queue(self):
+ return self.event.client.bot.coda
+
+ @property
+ def reply(self):
+ return self.event.reply
+
def run(self):
raise RuntimeError("Must be implemented!")
- def put_results(self, data):
+ def put_results(self, *data):
"""Task output will be sent to the main thread via the configured
queue; data should be a string containing the full output, that will
later be splitted on newlines."""
- unit = (self.connection_name, data)
- self.queue.put(unit)
+ self.queue.put(tuple(data))
class TestTask(Task):