]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/extras/Evergreen.py
lp1777675 inventory date support
[working/Evergreen.git] / Open-ILS / src / extras / Evergreen.py
1 """
2 Evergreen IRC Interface plugin for supybot
3 """
4
5 import supybot
6
7 import urllib
8 import xml.dom.minidom
9 import re
10
11 __revision__ = "$Id$"
12 __author__ = 'PINES'
13 __contributors__ = {}
14
15 import supybot.conf as conf
16 import supybot.utils as utils
17 from supybot.commands import *
18 import supybot.plugins as plugins
19 import supybot.ircutils as ircutils
20 import supybot.ircmsgs as ircmsgs
21 import supybot.privmsgs as privmsgs
22 import supybot.registry as registry
23 import supybot.callbacks as callbacks
24
25 def configure(advanced):
26     from supybot.questions import expect, anything, something, yn
27     conf.registerPlugin('Evergreen', True)
28
29 conf.registerPlugin('Evergreen')
30
31 class Evergreen(callbacks.PrivmsgCommandAndRegexp):
32     threaded = True
33     def __init__(self):
34         self.__parent = super(Evergreen, self)
35         self.__parent.__init__()
36         #super(Evergreen, self).__init__()
37
38     def callCommand(self, name, irc, msg, *L, **kwargs):
39         self.__parent.callCommand(name, irc, msg, *L, **kwargs)
40
41     def osearch(self, irc, msg, args, word):
42         """<terms>
43
44         Performs an OpenSearch against Evergreen for <terms>.
45         """
46         url = 'http://192.168.2.112/opensearch/?target=mr_result&mr_search_type=keyword&mr_search_query=' + urllib.quote(word) + '&page=1&mr_search_depth=0&mr_search_location=1&pagesize=5&max_rank=100'
47         irc.reply( 'Searching for ' + word + '...' );
48         rss = urllib.urlopen( url )
49         dom = xml.dom.minidom.parseString( rss.read() )
50         regexp = re.compile(r'http://tinyurl.com/\w+');
51         for item in dom.getElementsByTagName('item'):
52             title = item.getElementsByTagName('title')[0]
53             link = item.getElementsByTagName('link')[0]
54             f = urllib.urlopen('http://tinyurl.com/create.php?url='+link.firstChild.data)
55             tiny = regexp.search( f.read() ).group(0)
56             s = title.firstChild.data
57             s += " | " + tiny
58             irc.reply( s )
59
60     osearch = wrap(osearch, ['Text'])
61 Class = Evergreen