Merge pull request #2 from GLolol/python3

Add Python 3 support
This commit is contained in:
spline 2014-11-04 14:37:32 -05:00
commit f4cbfcdedc
4 changed files with 11 additions and 10 deletions

View File

@ -1,6 +1,7 @@
language: python
python:
- "2.7"
- "3.4"
- pypy
# command to install dependencies,
install:

View File

@ -25,11 +25,11 @@ __author__ = supybot.authors.unknown
__contributors__ = {}
# This is a url where the most recent plugin package can be downloaded.
__url__ = '' # 'http://supybot.com/Members/yourname/UrbanDictionary/download'
__url__ = ''
import config
import plugin
reload(config)
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!
@ -40,5 +40,4 @@ if world.testing:
Class = plugin.Class
configure = config.configure
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:

View File

@ -22,6 +22,6 @@ def configure(advanced):
UrbanDictionary = conf.registerPlugin('UrbanDictionary')
conf.registerGlobalValue(UrbanDictionary, 'maxNumberOfDefinitions', registry.Integer(10, """Number of definition and examples in output. Max 10."""))
conf.registerGlobalValue(UrbanDictionary, 'disableANSI', registry.Boolean(False, """Do not display any ANSI (color/bold) in output."""))
conf.registerGlobalValue(UrbanDictionary, 'disableANSI', registry.Boolean(False, """Do not display any ANSI formatting codes in output."""))
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=250:

View File

@ -5,6 +5,7 @@
#
#
###
from __future__ import unicode_literals
# my libs
import json
import re
@ -111,7 +112,7 @@ class UrbanDictionary(callbacks.Plugin):
try:
jsondata = self._repairjson(html.decode('utf-8')) # decode utf-8. fix \r\n that ud puts in below.
jsondata = json.loads(jsondata) # odds chars in UD.
except Exception, e:
except Exception as e:
self.log.error("Error parsing JSON from UD: {0}".format(e))
irc.reply("ERROR: Failed to parse json data. Check logs for error")
return
@ -122,15 +123,15 @@ class UrbanDictionary(callbacks.Plugin):
if results == "exact": # we did not find anything.
outdefs = []
for i in definitions[0:args['numberOfDefinitions']]: # iterate through each def.
outputstring = "{0}".format(i['definition'].encode('utf-8').strip()) # default string.
outputstring = "{0}".format(i['definition'].strip()) # default string.
if args['showExamples']: # show examples?
outputstring += " {0} {1} {2}".format(self._bu("[ex:]"), i['example'].encode('utf-8').strip(), self._bu("[/ex]"))
outputstring += " {0} {1} {2}".format(self._bu("[ex:]"), i['example'].strip(), self._bu("[/ex]"))
if args['showVotes']: # show votes?
outputstring += " (+{0}/-{1})".format(i['thumbs_up'], i['thumbs_down'])
outdefs.append(outputstring) # add to our list.
output = " | ".join([item for item in outdefs]) # create string with everything.
elif results == "fulltext": # not direct. yields related terms.
output = " | ".join(sorted(set([item['word'].encode('utf-8') for item in definitions]))) # sorted, unique words.
output = " | ".join(sorted(set([item['word'] for item in definitions]))) # sorted, unique words.
# output time.
if results == "no_results" or len(definitions) == 0: # NOTHING FOUND.
irc.reply("ERROR: '{0}' not defined on UrbanDictionary.".format(optterm))