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
|
from heapq import nlargest as _nlargest
|
||||||
|
|
||||||
class ChefMou(Plugin):
|
class ChefMou(Plugin):
|
||||||
|
listRemove = ["", "Souba", "Basse", "Trombone", "Trompette", "Sax Mib", "Clarinette", "Midi", "Original", "Enregistrement", "Paroles", "Commentaire"]
|
||||||
async def start(self) -> None:
|
async def start(self) -> None:
|
||||||
self.on_external_config_update()
|
self.on_external_config_update()
|
||||||
|
|
||||||
@@ -43,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()
|
||||||
@@ -56,12 +57,13 @@ class ChefMou(Plugin):
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
self.log.info("Commande : " + pattern)
|
||||||
if pattern == "morceau":
|
if pattern == "morceau":
|
||||||
soup = await self.get_site_content()
|
soup = await self.get_site_content()
|
||||||
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(
|
||||||
@@ -74,25 +76,30 @@ class ChefMou(Plugin):
|
|||||||
return
|
return
|
||||||
soup = await self.get_site_content()
|
soup = await self.get_site_content()
|
||||||
# Récuperer liste morceaux
|
# 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
|
# Object bts en str
|
||||||
parsedList=[]
|
parsedList=[]
|
||||||
originalList=[]
|
originalList=[]
|
||||||
for ts in s:
|
for ts in s:
|
||||||
|
if ts.text in self.listRemove :
|
||||||
|
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 :
|
||||||
|
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')
|
||||||
idx = 9
|
idx = 25
|
||||||
if chunks[1].lower() == "souba" or chunks[1].lower() == "soubassophone" or chunks[1].lower() == "sb":
|
if chunks[1].lower() == "souba" or chunks[1].lower() == "soubassophone" or chunks[1].lower() == "sb":
|
||||||
idx = 0
|
idx = 0
|
||||||
elif chunks[1].lower() == "basse" or chunks[1].lower() == "bs" :
|
elif chunks[1].lower() == "basse" or chunks[1].lower() == "bs" :
|
||||||
@@ -112,7 +119,7 @@ class ChefMou(Plugin):
|
|||||||
try :
|
try :
|
||||||
await evt.respond("["+originalList[idxTitre[0]]+ " " + chunks[1]+"]"+"(<https://partoches.pustule.org"+t[idx].get("href")+">)")
|
await evt.respond("["+originalList[idxTitre[0]]+ " " + chunks[1]+"]"+"(<https://partoches.pustule.org"+t[idx].get("href")+">)")
|
||||||
except IndexError:
|
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:
|
else:
|
||||||
await evt.respond("Morceau non trouvé")
|
await evt.respond("Morceau non trouvé")
|
||||||
|
|||||||
Reference in New Issue
Block a user