import wikipedia

MAX_LEN = 350


@yui.command('wiki', 'wk', 'w')
def wiki(argv):
    """Prints summary of Wikipedia atricles. Usage: wiki [-lang] <article>"""
    lang = 'en'
    if len(argv) < 2:
        return

    # check if a language was given
    argv = argv[1:]
    if len(argv) > 1 and argv[0].startswith('-'):
        lang = argv[0][1:]
        argv = argv[1:]

    article = ' '.join(argv)
    try:
        wikipedia.set_lang(lang)
        summary = wikipedia.summary(article)
    except Exception as ex:
        return "Couldn't find an article for '%s'" % article
    if len(summary) > MAX_LEN:
        summary = summary[:MAX_LEN-3] + '...'
    return summary

import wikipedia

MAX_LEN = 350


@yui.threaded
@yui.command('wiki', 'wk', 'w')
def wiki(argv):
    """Prints summary of Wikipedia atricles. Usage: wiki [-lang] <article>"""
    lang = 'en'
    if len(argv) < 2:
        return

    # check if a language was given
    argv = argv[1:]
    if len(argv) > 1 and argv[0].startswith('-'):
        lang = argv[0][1:]
        argv = argv[1:]

    article = ' '.join(argv)
    try:
        wikipedia.set_lang(lang)
        summary = wikipedia.summary(article)
    except Exception as ex:
        return "Couldn't find an article for '%s'" % article
    if len(summary) > MAX_LEN:
        summary = summary[:MAX_LEN-3] + '...'
    return summary

make wiki plugin threaded