[syno] Dusting module
This commit is contained in:
parent
1ef54426bc
commit
00fa139e54
|
@ -1,7 +1,7 @@
|
||||||
# coding=utf-8
|
|
||||||
|
|
||||||
"""Find synonyms"""
|
"""Find synonyms"""
|
||||||
|
|
||||||
|
# PYTHON STUFFS #######################################################
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
|
@ -9,14 +9,10 @@ from nemubot.exception import IMException
|
||||||
from nemubot.hooks import hook
|
from nemubot.hooks import hook
|
||||||
from nemubot.tools import web
|
from nemubot.tools import web
|
||||||
|
|
||||||
nemubotversion = 4.0
|
|
||||||
|
|
||||||
from more import Response
|
from more import Response
|
||||||
|
|
||||||
|
|
||||||
def help_full():
|
# LOADING #############################################################
|
||||||
return "!syno [LANG] <word>: give a list of synonyms for <word>."
|
|
||||||
|
|
||||||
|
|
||||||
def load(context):
|
def load(context):
|
||||||
global lang_binding
|
global lang_binding
|
||||||
|
@ -30,6 +26,8 @@ def load(context):
|
||||||
lang_binding["en"] = lambda word: get_english_synos(context.config["bighugelabskey"], word)
|
lang_binding["en"] = lambda word: get_english_synos(context.config["bighugelabskey"], word)
|
||||||
|
|
||||||
|
|
||||||
|
# MODULE CORE #########################################################
|
||||||
|
|
||||||
def get_french_synos(word):
|
def get_french_synos(word):
|
||||||
url = "http://www.crisco.unicaen.fr/des/synonymes/" + quote(word.encode("ISO-8859-1"))
|
url = "http://www.crisco.unicaen.fr/des/synonymes/" + quote(word.encode("ISO-8859-1"))
|
||||||
page = web.getURLContent(url)
|
page = web.getURLContent(url)
|
||||||
|
@ -72,24 +70,29 @@ def get_english_synos(key, word):
|
||||||
lang_binding = { 'fr': get_french_synos }
|
lang_binding = { 'fr': get_french_synos }
|
||||||
|
|
||||||
|
|
||||||
@hook.command("synonymes", data="synonymes")
|
# MODULE INTERFACE ####################################################
|
||||||
@hook.command("antonymes", data="antonymes")
|
|
||||||
|
@hook.command("synonymes", data="synonymes",
|
||||||
|
help="give a list of synonyms",
|
||||||
|
help_usage={"WORD": "give synonyms of the given WORD"},
|
||||||
|
keywords={
|
||||||
|
"lang=LANG": "change the dictionnary language: default fr, available: " + ", ".join(lang_binding)
|
||||||
|
})
|
||||||
|
@hook.command("antonymes", data="antonymes",
|
||||||
|
help="give a list of antonyms",
|
||||||
|
help_usage={"WORD": "give antonyms of the given WORD"},
|
||||||
|
keywords={
|
||||||
|
"lang=LANG": "change the dictionnary language: default fr, available: " + ", ".join(lang_binding)
|
||||||
|
})
|
||||||
def go(msg, what):
|
def go(msg, what):
|
||||||
if not len(msg.args):
|
if not len(msg.args):
|
||||||
raise IMException("de quel mot veux-tu connaître la liste des synonymes ?")
|
raise IMException("de quel mot veux-tu connaître la liste des synonymes ?")
|
||||||
|
|
||||||
# Detect lang
|
lang = msg.kwargs["lang"] if "lang" in msg.kwargs else "fr"
|
||||||
if msg.args[0] in lang_binding:
|
word = ' '.join(msg.args)
|
||||||
func = lang_binding[msg.args[0]]
|
|
||||||
word = ' '.join(msg.args[1:])
|
|
||||||
else:
|
|
||||||
func = lang_binding["fr"]
|
|
||||||
word = ' '.join(msg.args)
|
|
||||||
# TODO: depreciate usage without lang
|
|
||||||
#raise IMException("language %s is not handled yet." % msg.args[0])
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
best, synos, anton = func(word)
|
best, synos, anton = lang_binding[lang](word)
|
||||||
except:
|
except:
|
||||||
best, synos, anton = (list(), list(), list())
|
best, synos, anton = (list(), list(), list())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user