Mostrar actual e total
This commit is contained in:
parent
2895f77026
commit
0897252d51
|
@ -46,9 +46,12 @@ from bs4 import BeautifulSoup
|
||||||
class Priberam(callbacks.Plugin):
|
class Priberam(callbacks.Plugin):
|
||||||
"""Priberam dictionary client"""
|
"""Priberam dictionary client"""
|
||||||
|
|
||||||
def __clean_str(self, text):
|
def __clean_str(self, text, clean_number=False):
|
||||||
text = re.sub(r'\s+', ' ', text)
|
text = re.sub(r'\s+', ' ', text)
|
||||||
text = re.sub(r'(\[.*?]) (\1)', r'\1', text)
|
text = re.sub(r'(\[.*?]) (\1)', r'\1', text)
|
||||||
|
text = re.sub(r'^\s+', '', text)
|
||||||
|
if clean_number:
|
||||||
|
text = re.sub(r'^\d+\. +', '', text)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def find(self, irc, msg, args, word, position):
|
def find(self, irc, msg, args, word, position):
|
||||||
|
@ -68,12 +71,19 @@ class Priberam(callbacks.Plugin):
|
||||||
return
|
return
|
||||||
|
|
||||||
definitions = soup.find('div', {'id': 'resultados'}).find_all('p')
|
definitions = soup.find('div', {'id': 'resultados'}).find_all('p')
|
||||||
if position > len(definitions):
|
|
||||||
|
total = 0
|
||||||
|
for idx in range(len(definitions)):
|
||||||
|
if idx > 1 and self.__clean_str(definitions[idx].text)[:1].isdigit() is False:
|
||||||
|
break
|
||||||
|
total += 1
|
||||||
|
|
||||||
|
if position > total:
|
||||||
return
|
return
|
||||||
|
|
||||||
definition = self.__clean_str(definitions[position - 1].text)
|
definition = self.__clean_str(definitions[position - 1].text, True)
|
||||||
|
|
||||||
irc.reply(definition, prefixNick=False)
|
irc.reply("[{}/{}] {}".format(position, total, definition), prefixNick=False)
|
||||||
find = wrap(find, ['anything', optional('int', default=1)])
|
find = wrap(find, ['anything', optional('int', default=1)])
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue