Skip to content

Commit 29f4154

Browse files
committed
Added 1890 tlf plugin
1 parent a7f30c4 commit 29f4154

File tree

5 files changed

+255
-0
lines changed

5 files changed

+255
-0
lines changed

Tlf/LICENCE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Eiffel Forum License, version 2
2+
3+
1. Permission is hereby granted to use, copy, modify and/or distribute this
4+
package, provided that:
5+
* copyright notices are retained unchanged,
6+
* any distribution of this package, whether modified or not, includes
7+
this license text.
8+
2. Permission is hereby also granted to distribute binary programs which
9+
depend on this package. If the binary program depends on a modified
10+
version of this package, you are encouraged to publicly release the
11+
modified version of this package.
12+
13+
***********************
14+
15+
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT WARRANTY. ANY EXPRESS OR IMPLIED
16+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
18+
SHALL THE AUTHORS BE LIABLE TO ANY PARTY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
20+
OF THIS PACKAGE.
21+
***********************

Tlf/__init__.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
###
2+
# Copyright (c) 2008, emh
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice,
9+
# this list of conditions, and the following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions, and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
# * Neither the name of the author of this software nor the name of
14+
# contributors to this software may be used to endorse or promote products
15+
# derived from this software without specific prior written consent.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
29+
###
30+
31+
"""
32+
Add a description of the plugin (to be presented to the user inside the wizard)
33+
here. This should describe *what* the plugin does.
34+
"""
35+
36+
import supybot
37+
import supybot.world as world
38+
39+
# Use this for the version of this plugin. You may wish to put a CVS keyword
40+
# in here if you're keeping the plugin in CVS or some similar system.
41+
__version__ = ""
42+
43+
# XXX Replace this with an appropriate author or supybot.Author instance.
44+
__author__ = supybot.authors.unknown
45+
46+
# This is a dictionary mapping supybot.Author instances to lists of
47+
# contributions.
48+
__contributors__ = {}
49+
50+
# This is a url where the most recent plugin package can be downloaded.
51+
__url__ = '' # 'http://supybot.com/Members/yourname/WTF8/download'
52+
53+
import config
54+
import plugin
55+
reload(plugin) # In case we're being reloaded.
56+
# Add more reloads here if you add third-party modules and want them to be
57+
# reloaded when this plugin is reloaded. Don't forget to import them as well!
58+
59+
if world.testing:
60+
import test
61+
62+
Class = plugin.Class
63+
configure = config.configure
64+
65+
66+
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

Tlf/config.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
###
2+
# Copyright (c) 2008, emh
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice,
9+
# this list of conditions, and the following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions, and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
# * Neither the name of the author of this software nor the name of
14+
# contributors to this software may be used to endorse or promote products
15+
# derived from this software without specific prior written consent.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
29+
###
30+
31+
import supybot.conf as conf
32+
import supybot.registry as registry
33+
34+
def configure(advanced):
35+
# This will be called by supybot to configure this module. advanced is
36+
# a bool that specifies whether the user identified himself as an advanced
37+
# user or not. You should effect your configuration by manipulating the
38+
# registry as appropriate.
39+
from supybot.questions import expect, anything, something, yn
40+
conf.registerPlugin('Tlf', True)
41+
42+
43+
WTF8 = conf.registerPlugin('Tlf')
44+
# This is where your configuration variables (if any) should go. For example:
45+
# conf.registerGlobalValue(WTF8, 'someConfigVariableName',
46+
# registry.Boolean(False, """Help for someConfigVariableName."""))
47+
48+
49+
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

Tlf/plugin.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
# Copyright (c) 2008, emh
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice,
9+
# this list of conditions, and the following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions, and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
# * Neither the name of the author of this software nor the name of
14+
# contributors to this software may be used to endorse or promote products
15+
# derived from this software without specific prior written consent.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
29+
###
30+
31+
'''
32+
lookup norwegian phone numbers
33+
'''
34+
35+
import supybot.utils as utils
36+
#from supybot.commands import *
37+
from supybot import commands
38+
import supybot.plugins as plugins
39+
import supybot.ircutils as ircutils
40+
import supybot.callbacks as callbacks
41+
import supybot.ircmsgs as ircmsgs
42+
43+
#sys.path.insert('/home/alexis/plugins/WTF8')
44+
import BeautifulSoup, sys, re, urllib
45+
46+
class AttenNittiParser:
47+
def __init__(self):
48+
self.soup = BeautifulSoup.BeautifulSoup()
49+
50+
def lookup(self, tlf):
51+
""" Lookup using http get variables contained in data """
52+
url = "http://1890.no/?type=Privat&query=%d" % tlf
53+
data = urllib.urlopen(url).read()
54+
55+
self.soup.feed(data.decode("UTF-8"))
56+
interesting_row = self.soup.find(attrs={"class": re.compile(".*vcard.*")})
57+
58+
data = dict([(x.attrs[0][1], x.text) for x in interesting_row.findAll("span") ])
59+
return data
60+
61+
62+
class Tlf(callbacks.Plugin):
63+
"""Add the help for "@plugin help Tlf" here
64+
This should describe *how* to use this plugin."""
65+
66+
def tlf(self, irc, msg, args, opts, lookup):
67+
'''
68+
<tlf number>
69+
'''
70+
71+
parser = AttenNittiParser()
72+
data = parser.lookup(int(lookup))
73+
reply = ', '.join([ "%s: %s" % (k.encode("UTF-8"), v.encode("UTF-8")) for k, v in data.items() ])
74+
if reply:
75+
irc.reply(reply, prefixNick=False)
76+
77+
tlf = commands.wrap(tlf, [commands.getopts({}), 'text'])
78+
79+
Class = Tlf
80+
81+
82+
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

Tlf/test.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
###
2+
# Copyright (c) 2008, emh
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice,
9+
# this list of conditions, and the following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions, and the following disclaimer in the
12+
# documentation and/or other materials provided with the distribution.
13+
# * Neither the name of the author of this software nor the name of
14+
# contributors to this software may be used to endorse or promote products
15+
# derived from this software without specific prior written consent.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
29+
###
30+
31+
from supybot.test import *
32+
33+
class TlfTestCase(PluginTestCase):
34+
plugins = ('Tlf',)
35+
36+
37+
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

0 commit comments

Comments
 (0)