-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
conjugueur.py
60 lines (51 loc) · 1.76 KB
/
conjugueur.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
"""conjugueur.py
This script display the french conjugation of known verb to
Grammalecte. It requires the grammalecte package.
Copyright (C) 2018+ Étienne Deparis <[email protected]>
This is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
"""
import sys
from grammalecte.fr.conj import Verb
def print_forms(data, forms):
for p in forms:
if p in data and data[p] != "":
print("- " + data[p])
if __name__ == "__main__":
if len(sys.argv) != 2:
sys.exit(1)
try:
v = Verb(sys.argv[1])
except (TypeError, ValueError):
print("Verbe non trouvé")
sys.exit()
if v.sVerb in ["être", "avoir"]:
print("* {} · {}".format(v.sVerb, v.sInfo))
else:
print("* {} · verbe du {}".format(v.sVerb, v.sInfo))
print()
for k, data in v.dConj.items():
if k == ":Y":
continue
print("** " + data["label"] + "\n")
if k == ":P":
if k in data:
# Newer version of Grammalecte (2.1.1+)
print(data[k])
else:
# Older version
print(data[":"])
if k == ":Q":
print("À conjuguer avec l’auxiliaire *{}* :\n".format(v.sVerbAux))
if ":m:s" in data:
# Newer version of Grammalecte (2.1.1+)
print_forms(data, [":f:s", ":f:p", ":m:s", ":m:p"])
else:
# Older version
print_forms(data, [":Q3", ":Q4", ":Q1", ":Q2"])
else:
print_forms(data, [":1s", ":2s", ":3s", ":1p", ":2p", ":3p"])
print()