Compare commits

...

5 Commits

Author SHA1 Message Date
Valentin Lorentz 2486c2dadf WikiTrans: Fix Python 3 compatibility. 2014-04-16 07:52:03 +00:00
Valentin Lorentz bf72337923 travis.yml: Excluse plugin NoLatin1. 2014-04-16 07:49:26 +00:00
Valentin Lorentz 7f8fcfd54c Twitter: Catch SyntaxError exceptions and raise callbacks.Error instead. 2014-04-16 07:21:15 +00:00
Valentin Lorentz e0b1c998a7 TwitterStream: Catch ImportError/SyntaxError exceptions and raise callbacks.Error instead. 2014-04-16 07:16:12 +00:00
Valentin Lorentz d0c986aee6 Darkfallonline: Remove plugin. 2014-04-16 07:07:28 +00:00
8 changed files with 22 additions and 299 deletions

View File

@ -11,4 +11,4 @@ install:
# command to run tests, e.g. python setup.py test
script:
- echo $TRAVIS_PYTHON_VERSION
- supybot-test --plugins-dir=. --no-network --exclude=WebStats --exclude=Seeks --exclude=Rbls --exclude=MilleBornes --exclude=Scheme --exclude=Twitter --exclude=TwitterStream --exclude=MegaHAL --exclude=Darkfallonline --exclude=Webstats --exclude=Darkfallonline
- supybot-test --plugins-dir=. --no-network --exclude=WebStats --exclude=Seeks --exclude=Rbls --exclude=MilleBornes --exclude=Scheme --exclude=Twitter --exclude=TwitterStream --exclude=MegaHAL --exclude=Webstats --exclude=NoLatin1

View File

@ -1,67 +0,0 @@
###
# Copyright (c) 2012, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
"""
Add a description of the plugin (to be presented to the user inside the wizard)
here. This should describe *what* the plugin does.
"""
import supybot
import supybot.world as world
# Use this for the version of this plugin. You may wish to put a CVS keyword
# in here if you're keeping the plugin in CVS or some similar system.
__version__ = ""
# XXX Replace this with an appropriate author or supybot.Author instance.
__author__ = supybot.authors.unknown
# This is a dictionary mapping supybot.Author instances to lists of
# contributions.
__contributors__ = {}
# This is a url where the most recent plugin package can be downloaded.
__url__ = '' # 'http://supybot.com/Members/yourname/Darkfallonline/download'
from . import config
from . import plugin
from imp import reload
reload(plugin) # In case we're being reloaded.
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!
if world.testing:
from . import test
Class = plugin.Class
configure = config.configure
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

View File

@ -1,52 +0,0 @@
###
# Copyright (c) 2012, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
import supybot.conf as conf
import supybot.registry as registry
from supybot.i18n import PluginInternationalization, internationalizeDocstring
_ = PluginInternationalization('Darkfallonline')
def configure(advanced):
# This will be called by supybot to configure this module. advanced is
# a bool that specifies whether the user identified himself as an advanced
# user or not. You should effect your configuration by manipulating the
# registry as appropriate.
from supybot.questions import expect, anything, something, yn
conf.registerPlugin('Darkfallonline', True)
Darkfallonline = conf.registerPlugin('Darkfallonline')
# This is where your configuration variables (if any) should go. For example:
# conf.registerGlobalValue(Darkfallonline, 'someConfigVariableName',
# registry.Boolean(False, _("""Help for someConfigVariableName.""")))
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

View File

@ -1,138 +0,0 @@
###
# Copyright (c) 2012, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
import requests
from BeautifulSoup import BeautifulSoup
import supybot.utils as utils
import supybot.world as world
from supybot.commands import *
import supybot.plugins as plugins
import supybot.ircmsgs as ircmsgs
import supybot.schedule as schedule
import supybot.ircutils as ircutils
import supybot.callbacks as callbacks
from supybot.i18n import PluginInternationalization, internationalizeDocstring
_ = PluginInternationalization('Darkfallonline')
servers = (('US1', 'http://www.us1.darkfallonline.com/news'),
('EU1', 'http://www.eu1.darkfallonline.com/news'),
)
login = 'https://ams.darkfallonline.com/AMS/'
CHANNEL = '#progval'
def check_status(url):
up = False
soup = BeautifulSoup(requests.get(url).text)
status = "players"
server = "US1"
status = {'players': False, 'gms': False, 'mastergms': False,
'admins': False}
for img in soup.findAll('img'):
for type_ in status:
if img["src"].startswith("images/%s_online" % type_):
status[type_] = True
return status
def check_login_status(url):
return requests.head(url).status_code == 200
def write_errors(f):
def newf(*args, **kwargs):
try:
f(*args, **kwargs)
except Exception as e:
import traceback
traceback.print_exc(e)
return
return newf
@internationalizeDocstring
class Darkfallonline(callbacks.Plugin):
"""Add the help for "@plugin help Darkfallonline" here
This should describe *how* to use this plugin."""
threaded = True
def __init__(self, irc):
super(Darkfallonline, self).__init__(irc)
self._state = {}
for server, url in servers:
self._state[server] = check_status(url)
self._login = check_login_status(login)
schedule.addPeriodicEvent(self._announcer, 10,
'Darkfallonline_checkstatus')
def die(self):
schedule.removeEvent('Darkfallonline_checkstatus')
@write_errors
def _announcer(self):
for server, url in servers:
status = self._state[server]
new_status = check_status(url)
for irc in world.ircs:
if CHANNEL in irc.state.channels:
for type_ in new_status:
if new_status[type_] == status[type_]:
continue
elif new_status[type_]:
msg = '[%s] %s is going up' % (server,
type_.capitalize())
else:
msg = '[%s] %s is going down' % (server,
type_.capitalize())
irc.queueMsg(ircmsgs.privmsg(CHANNEL, msg))
self._state[server] = new_status
new_login_status = check_login_status(login)
if new_login_status == self._login:
pass
elif new_login_status:
irc.queueMsg(ircmsgs.privmsg(CHANNEL, '[login] Going up'))
else:
irc.queueMsg(ircmsgs.privmsg(CHANNEL, '[login] Going down'))
self._login = new_login_status
def status(self, irc, msg, args):
"""takes no arguments
Return the status of all servers."""
for server, status in self._state.items():
irc.reply('Up on %s: %s' % (server,
format('%L', [x.capitalize() for x,y in status.items() if y]) or 'none'),
private=True)
irc.reply('Login: %s' % ('on' if self._login else 'off'), private=True)
Class = Darkfallonline
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -1,37 +0,0 @@
###
# Copyright (c) 2012, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
from supybot.test import *
class DarkfallonlineTestCase(PluginTestCase):
plugins = ('Darkfallonline',)
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

View File

@ -67,6 +67,8 @@ try:
import twitter
except ImportError:
raise callbacks.Error('You need the python-twitter library.')
except Exception as e:
raise callbacks.Error('Unknown exception importing twitter: %r' % e)
reload(twitter)
if not hasattr(twitter, '__version__') or \
twitter.__version__.split('.') < ['0', '8', '0']:

View File

@ -28,9 +28,6 @@
###
import twitter
import requests
import supybot.utils as utils
import supybot.schedule as schedule
from supybot.commands import *
@ -38,6 +35,19 @@ import supybot.plugins as plugins
import supybot.ircutils as ircutils
import supybot.callbacks as callbacks
from supybot.i18n import PluginInternationalization, internationalizeDocstring
try:
import twitter
except ImportError:
raise callbacks.Error('You have to install python-twitter.')
except Exception as e:
raise callbacks.Error('Unknown exception importing twitter: %r' % e)
try:
import requests
except ImportError:
raise callbacks.Error('You have to install python-requests.')
except Exception as e:
raise callbacks.Error('Unknown exception importing requests: %r' % e)
_ = PluginInternationalization('TwitterStream')

View File

@ -42,6 +42,11 @@ _ = PluginInternationalization('WikiTrans')
import urllib
from xml.dom import minidom
if sys.version_info[0] == 2:
quote_plus = urllib.quote_plus
else:
quote_plus = urllib.parse.quote_plus
class WordNotFound(Exception):
pass
class Untranslatable(Exception):
@ -56,7 +61,7 @@ url = 'http://%s.wikipedia.org/w/api.php?action=query&format=xml&' + \
def translate(src, target, word):
try:
node = minidom.parse(utils.web.getUrlFd(url % (src,
urllib.quote_plus(word))))
quote_plus(word))))
except:
# Usually an urllib error
raise WordNotFound()