diff options
Diffstat (limited to 'files/.task/hooks/on-add-spell-check.py')
| -rwxr-xr-x | files/.task/hooks/on-add-spell-check.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/files/.task/hooks/on-add-spell-check.py b/files/.task/hooks/on-add-spell-check.py new file mode 100755 index 0000000..16758f0 --- /dev/null +++ b/files/.task/hooks/on-add-spell-check.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +from glob import glob +from os.path import isfile, splitext +import os +import re +import sys + +try: + from hunspell import HunSpell + from tasklib import Task, local_zone +except ImportError as e: + print(e) + sys.exit(0) + + +DICT_PATH = '/usr/share/hunspell/' +LANGS = ['en_US', 'ru_RU'] +ENV_SKIP = 'TW_IGNORE_SPELL' + + +def spellcheck(text): + spells = [] + for dic in glob(DICT_PATH + '*.dic'): + aff = splitext(dic)[0] + '.aff' + if isfile(dic) and isfile(aff): + spells.append(HunSpell(dic, aff)) + + if len(spells) == 0: + return + + errors = [] + + for word in re.findall(r'\w+', text): + ok = False + for spell in spells: + if spell.spell(word): + ok = True + break + if not ok: + errors.append(word) + + return errors + +task = Task.from_input() +errors = spellcheck(task['description']) +if len(errors) > 0: + print('Spell errors:', ', '.join(errors)) + if not ENV_SKIP in os.environ: + sys.exit(1) +print(task.export_data()) |
