wikipedia suche erlaubt mehrere worte als argument
This commit is contained in:
parent
933eb8b3fc
commit
ce79ce07fb
1 changed files with 16 additions and 14 deletions
|
@ -49,31 +49,32 @@ class Plugin(Plugin):
|
|||
|
||||
def run(self, stanza):
|
||||
'''
|
||||
Startfunktion des Plugins. Bekommt eine xmpp Stanza übergeben,
|
||||
extrahiert daraus den Nick des Absenders und aus dem Body den
|
||||
gewünschten Suchstring. Ist die Stringlänge ungleich Null oder
|
||||
False, wird beides dem Thread zur Wikipedia-Anfrage übergeben und
|
||||
eine Nachricht für den MUC zurück gegeben.
|
||||
param 1: xmpp stanza objekt
|
||||
returns: string
|
||||
'''
|
||||
lang = 'de'
|
||||
pattern = None
|
||||
call_msg = 'Call "!help {}"'.format(self.get_command())
|
||||
no_args_msg = ' '.join(('No search pattern!', call_msg))
|
||||
|
||||
muc_nick = common.get_nick_from_stanza(stanza)
|
||||
arguments = common.get_arguments_from_body(stanza)
|
||||
logging.debug('Arguments: {}'.format(arguments))
|
||||
|
||||
if arguments is False:
|
||||
if arguments is False or len(arguments) == 0:
|
||||
logging.warning('No arguments for wp search. Abort.')
|
||||
self.callback(': '.join((muc_nick, no_args_msg)))
|
||||
return
|
||||
msg = ' '.join(('No search pattern!', call_msg))
|
||||
else:
|
||||
if len(arguments) == 1:
|
||||
pattern = arguments[0]
|
||||
elif len(arguments) > 1:
|
||||
logging.warning('Not implemented yet.')
|
||||
self.callback('Not implemented yet')
|
||||
return
|
||||
logging.debug('Start thread for wp search')
|
||||
self.callback('Search started')
|
||||
api_thread = ApiThread(self.callback)
|
||||
api_thread.run(lang, pattern, muc_nick)
|
||||
pattern = ' '.join(arguments)
|
||||
api_thread = ApiThread(self.callback)
|
||||
api_thread.run(lang, pattern, muc_nick)
|
||||
msg = ' '.join(('Search started for:', pattern))
|
||||
self.callback(': '.join((muc_nick, msg)))
|
||||
return
|
||||
|
||||
|
||||
class ApiThread(threading.Thread):
|
||||
|
@ -88,6 +89,7 @@ class ApiThread(threading.Thread):
|
|||
'''
|
||||
Starts the thread.
|
||||
'''
|
||||
logging.debug('Start thread for wp search')
|
||||
data = self.get_file(lang, pattern)
|
||||
if data == False:
|
||||
self.callback('Error while connecting WP')
|
||||
|
|
Loading…
Reference in a new issue