Mostrar actual e total

This commit is contained in:
Pedro de Oliveira 2019-06-06 22:53:17 +01:00
parent 2895f77026
commit 0897252d51
1 changed files with 14 additions and 4 deletions

View File

@ -46,9 +46,12 @@ from bs4 import BeautifulSoup
class Priberam(callbacks.Plugin):
"""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'(\[.*?]) (\1)', r'\1', text)
text = re.sub(r'^\s+', '', text)
if clean_number:
text = re.sub(r'^\d+\. +', '', text)
return text
def find(self, irc, msg, args, word, position):
@ -68,12 +71,19 @@ class Priberam(callbacks.Plugin):
return
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
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)])