Compare commits
5 Commits
94a51fcaf8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61676f2374 | ||
|
|
57d889340d | ||
|
|
48ed397bc8 | ||
|
|
3718a745b2 | ||
|
|
df382d7f53 |
21
chef_mou.py
21
chef_mou.py
@@ -11,6 +11,7 @@ from difflib import SequenceMatcher
|
||||
from heapq import nlargest as _nlargest
|
||||
|
||||
class ChefMou(Plugin):
|
||||
listRemove = ["", "Souba", "Basse", "Trombone", "Trompette", "Sax Mib", "Clarinette", "Midi", "Original", "Enregistrement", "Paroles", "Commentaire"]
|
||||
async def start(self) -> None:
|
||||
self.on_external_config_update()
|
||||
|
||||
@@ -43,7 +44,7 @@ class ChefMou(Plugin):
|
||||
|
||||
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)
|
||||
async def morceau(self, evt: MessageEvent, pattern: str) -> None:
|
||||
loop = asyncio.new_event_loop()
|
||||
@@ -56,12 +57,13 @@ class ChefMou(Plugin):
|
||||
"""
|
||||
)
|
||||
else:
|
||||
self.log.info("Commande : " + pattern)
|
||||
if pattern == "morceau":
|
||||
soup = await self.get_site_content()
|
||||
s = soup.findAll('th', background='/fond3.gif')
|
||||
ps = random.choice(s)
|
||||
await evt.respond(ps.text)
|
||||
elif pattern.__contains__("partition"):
|
||||
elif pattern.__contains__("part"):
|
||||
chunks = pattern.split(None, 2)
|
||||
if len(chunks) != 3 :
|
||||
await evt.respond(
|
||||
@@ -74,25 +76,30 @@ class ChefMou(Plugin):
|
||||
return
|
||||
soup = await self.get_site_content()
|
||||
# Récuperer liste morceaux
|
||||
s = soup.select('th', background='/fond3.gif')
|
||||
#s = soup.select('th', background='/fond3.gif')
|
||||
s = soup.select('th')
|
||||
# Object bts en str
|
||||
parsedList=[]
|
||||
originalList=[]
|
||||
for ts in s:
|
||||
if ts.text in self.listRemove :
|
||||
continue
|
||||
fullTitre = ts.text
|
||||
#Supression des ()
|
||||
parsedList.append(re.sub("[\(\[].*?[\)\]]", "", fullTitre))
|
||||
parsedList.append(re.sub("[\(\[].*?[\)\]]", "", fullTitre).lower())
|
||||
#On garde une copie pour la recherche
|
||||
originalList.append(ts.text)
|
||||
|
||||
# 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
|
||||
if len(idxTitre) > 0 :
|
||||
for el in idxTitre :
|
||||
self.log.info(originalList[el] + ': ' + str(SequenceMatcher(None, chunks[2], parsedList[el]).ratio()))
|
||||
#Et on recherche dans la liste originale avec le titre original
|
||||
s = soup.find('th', string=originalList[idxTitre[0]])
|
||||
t = s.parent.findAll('a')
|
||||
idx = 9
|
||||
idx = 25
|
||||
if chunks[1].lower() == "souba" or chunks[1].lower() == "soubassophone" or chunks[1].lower() == "sb":
|
||||
idx = 0
|
||||
elif chunks[1].lower() == "basse" or chunks[1].lower() == "bs" :
|
||||
@@ -112,7 +119,7 @@ class ChefMou(Plugin):
|
||||
try :
|
||||
await evt.respond("["+originalList[idxTitre[0]]+ " " + chunks[1]+"]"+"(<https://partoches.pustule.org"+t[idx].get("href")+">)")
|
||||
except IndexError:
|
||||
await evt.respond("Le morceau "+ strTitre[0] + " existe mais pas ta partoche")
|
||||
await evt.respond("Le morceau "+ originalList[idxTitre[0]] + " existe mais pas ta partoche")
|
||||
|
||||
else:
|
||||
await evt.respond("Morceau non trouvé")
|
||||
|
||||
Reference in New Issue
Block a user