Compare commits
3 Commits
3718a745b2
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61676f2374 | ||
|
|
57d889340d | ||
|
|
48ed397bc8 |
10
chef_mou.py
10
chef_mou.py
@@ -44,7 +44,7 @@ class ChefMou(Plugin):
|
|||||||
|
|
||||||
return BeautifulSoup(text.decode('iso-8859-1'), 'html.parser')
|
return BeautifulSoup(text.decode('iso-8859-1'), 'html.parser')
|
||||||
|
|
||||||
@command.new("chefmou")
|
@command.new(aliases=["chefmou","chefmu","cm"])
|
||||||
@command.argument("pattern", pass_raw=True, required=False)
|
@command.argument("pattern", pass_raw=True, required=False)
|
||||||
async def morceau(self, evt: MessageEvent, pattern: str) -> None:
|
async def morceau(self, evt: MessageEvent, pattern: str) -> None:
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
@@ -63,7 +63,7 @@ class ChefMou(Plugin):
|
|||||||
s = soup.findAll('th', background='/fond3.gif')
|
s = soup.findAll('th', background='/fond3.gif')
|
||||||
ps = random.choice(s)
|
ps = random.choice(s)
|
||||||
await evt.respond(ps.text)
|
await evt.respond(ps.text)
|
||||||
elif pattern.__contains__("partition"):
|
elif pattern.__contains__("part"):
|
||||||
chunks = pattern.split(None, 2)
|
chunks = pattern.split(None, 2)
|
||||||
if len(chunks) != 3 :
|
if len(chunks) != 3 :
|
||||||
await evt.respond(
|
await evt.respond(
|
||||||
@@ -86,16 +86,16 @@ class ChefMou(Plugin):
|
|||||||
continue
|
continue
|
||||||
fullTitre = ts.text
|
fullTitre = ts.text
|
||||||
#Supression des ()
|
#Supression des ()
|
||||||
parsedList.append(re.sub("[\(\[].*?[\)\]]", "", fullTitre))
|
parsedList.append(re.sub("[\(\[].*?[\)\]]", "", fullTitre).lower())
|
||||||
#On garde une copie pour la recherche
|
#On garde une copie pour la recherche
|
||||||
originalList.append(ts.text)
|
originalList.append(ts.text)
|
||||||
|
|
||||||
# Fonction qui retourne l'index du string le plus proche
|
# Fonction qui retourne l'index du string le plus proche
|
||||||
idxTitre = self.get_close_matches_indexes(chunks[2], parsedList, cutoff=0.4)
|
idxTitre = self.get_close_matches_indexes(chunks[2].lower(), parsedList, cutoff=0.4)
|
||||||
# Si trouvé le chercher sinon erreur
|
# Si trouvé le chercher sinon erreur
|
||||||
if len(idxTitre) > 0 :
|
if len(idxTitre) > 0 :
|
||||||
for el in idxTitre :
|
for el in idxTitre :
|
||||||
self.log.info(parsedList[el] + ': ' + str(SequenceMatcher(None, chunks[2], parsedList[el]).ratio()))
|
self.log.info(originalList[el] + ': ' + str(SequenceMatcher(None, chunks[2], parsedList[el]).ratio()))
|
||||||
#Et on recherche dans la liste originale avec le titre original
|
#Et on recherche dans la liste originale avec le titre original
|
||||||
s = soup.find('th', string=originalList[idxTitre[0]])
|
s = soup.find('th', string=originalList[idxTitre[0]])
|
||||||
t = s.parent.findAll('a')
|
t = s.parent.findAll('a')
|
||||||
|
|||||||
Reference in New Issue
Block a user