Define a dictonary for the tens list
This commit is contained in:
parent
f6d4600df3
commit
fde217dfde
@ -7,9 +7,37 @@ from urllib.parse import quote
|
||||
|
||||
from tools import web
|
||||
from tools.web import striphtml
|
||||
from collections import defaultdict
|
||||
|
||||
nemubotversion = 3.3
|
||||
|
||||
dic = {'pr' : '0',
|
||||
'ps' : '12',
|
||||
'pa' : '112',
|
||||
'pc' : '100',
|
||||
'f' : '18',
|
||||
'fa' : '118',
|
||||
'spr' : '24',
|
||||
'spa' : '124',
|
||||
'ii' : '6',
|
||||
'pqp' : '106'}
|
||||
|
||||
s = [('present', '0'), ('présent', '0'), ('pr', '0'),
|
||||
('passé simple', '12'), ('passe simple', '12'), ('ps', '12'),
|
||||
('passé antérieur', '112'), ('passe anterieur', '112'), ('pa', '112'),
|
||||
('passé composé', '100'), ('passe compose', '100'), ('pc', '100'),
|
||||
('futur', '18'), ('f', '18'),
|
||||
('futur antérieur', '118'), ('futur anterieur', '118'), ('fa', '118'),
|
||||
('subjonctif présent', '24'), ('subjonctif present', '24'), ('spr', '24'),
|
||||
('subjonctif passé', '124'), ('subjonctif passe', '124'), ('spa', '124'),
|
||||
('plus que parfait', '106'), ('pqp', '106'),
|
||||
('imparfait', '6'), ('ii', '6')]
|
||||
|
||||
d = defaultdict(list)
|
||||
|
||||
for k, v in s:
|
||||
d[k].append(v)
|
||||
|
||||
def help_tiny ():
|
||||
return "Find french conjugaison"
|
||||
|
||||
@ -63,36 +91,24 @@ def get_conjug(verb, stringTens):
|
||||
|
||||
def compute_line(line, stringTens):
|
||||
res = list()
|
||||
idTemps = get_conjug_for_tens(stringTens)
|
||||
try:
|
||||
idTemps = d[stringTens]
|
||||
except:
|
||||
res.append("Le temps demandé n'existe pas")
|
||||
return res
|
||||
|
||||
if idTemps is None:
|
||||
return Response(msg.sender,
|
||||
"Le temps que vous avez spécifiez n'existe pas", msg.channel)
|
||||
if len(idTemps) == 0:
|
||||
res.append("Le temps demandé n'existe pas")
|
||||
return res
|
||||
|
||||
index = line.index('<div id="temps' + idTemps + '\"')
|
||||
index = line.index('<div id="temps' + idTemps[0] + '\"')
|
||||
endIndex = line[index:].index('<div class=\"conjugBloc\"')
|
||||
|
||||
endIndex += index
|
||||
newLine = line[index:endIndex]
|
||||
|
||||
for elt in re.finditer("[p|/]>([^/]*/b>)", newLine):
|
||||
# res.append(strip_tags(elt.group(1)))
|
||||
res.append(striphtml(elt.group(1)))
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def get_conjug_for_tens(stringTens):
|
||||
dic = {'pr' : '0',
|
||||
'ps' : '12',
|
||||
'pa' : '112',
|
||||
'pc' : '100',
|
||||
'f' : '18',
|
||||
'fa' : '118',
|
||||
'spr' : '24',
|
||||
'spa' : '124',
|
||||
'ii' : '6',
|
||||
'pqp' : '106'}
|
||||
|
||||
return dic[stringTens]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user