aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Bobov <anton@bobov.name>2025-03-02 23:54:03 +0500
committerAnton Bobov <anton@bobov.name>2025-03-02 23:54:03 +0500
commit42e9a414e612e8bf34941278f293b336daa68b84 (patch)
tree912ce18bc289faa45e8b1bdc088c0891ff929ae7
parentd1358a9d94fa86f80a068afcc7a9c101b2b4fc18 (diff)
task: Fix taskwarrior hooks
-rwxr-xr-xfiles/.task/hooks/on-add-default-time.py15
-rwxr-xr-xfiles/.task/hooks/on-add-spell-check.py26
2 files changed, 20 insertions, 21 deletions
diff --git a/files/.task/hooks/on-add-default-time.py b/files/.task/hooks/on-add-default-time.py
index ec2cc41..7f7aca9 100755
--- a/files/.task/hooks/on-add-default-time.py
+++ b/files/.task/hooks/on-add-default-time.py
@@ -1,26 +1,25 @@
#!/usr/bin/env python3
# Adopted from https://github.com/tbabej/task.default-date-time
from datetime import time
-from tasklib import Task, local_zone
+from tasklib import Task
DEFAULT_TIME = time(22, 0, 0)
def is_local_midnight(timestamp):
- return timestamp.astimezone(local_zone).time() == time(0, 0, 0)
+ return timestamp.astimezone().time() == time(0, 0, 0)
+
def set_default_time(timestamp):
- return timestamp.astimezone(local_zone).replace(
- hour=DEFAULT_TIME.hour,
- minute=DEFAULT_TIME.minute,
- second=DEFAULT_TIME.second
+ return timestamp.astimezone().replace(
+ hour=DEFAULT_TIME.hour, minute=DEFAULT_TIME.minute, second=DEFAULT_TIME.second
)
task = Task.from_input()
-if task['due'] and is_local_midnight(task['due']):
- task['due'] = set_default_time(task['due'])
+if task["due"] and is_local_midnight(task["due"]):
+ task["due"] = set_default_time(task["due"])
print("Default due time has been set.")
print(task.export_data())
diff --git a/files/.task/hooks/on-add-spell-check.py b/files/.task/hooks/on-add-spell-check.py
index 6ddb6de..8da631a 100755
--- a/files/.task/hooks/on-add-spell-check.py
+++ b/files/.task/hooks/on-add-spell-check.py
@@ -7,20 +7,20 @@ from os.path import isfile, splitext
try:
from hunspell import HunSpell
- from tasklib import Task, local_zone
+ from tasklib import Task
except ImportError as e:
print(e)
sys.exit(0)
-DICT_PATH = '/usr/share/hunspell/'
-LANGS = ['en_US', 'ru_RU']
-ENV_SKIP = 'TW_IGNORE_SPELL'
+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'
+ for dic in glob(DICT_PATH + "*.dic"):
+ aff = splitext(dic)[0] + ".aff"
if isfile(dic) and isfile(aff):
spells.append(HunSpell(dic, aff))
@@ -29,7 +29,7 @@ def spellcheck(text):
errors = []
- for word in re.findall(r'\w+', text):
+ for word in re.findall(r"\w+", text):
ok = False
for spell in spells:
if spell.spell(word):
@@ -43,17 +43,17 @@ def spellcheck(text):
def should_run_spellcheck(task):
if len(sys.argv) > 1:
- opts = dict(arg.split(':', 1) for arg in sys.argv[1:])
- command = opts['command']
- return command in ['add', 'append', 'log', 'modify', 'prepend']
+ opts = dict(arg.split(":", 1) for arg in sys.argv[1:])
+ command = opts["command"]
+ return command in ["add", "append", "log", "modify", "prepend"]
return False
task = Task.from_input()
if should_run_spellcheck(task):
- errors = spellcheck(task['description'])
+ errors = spellcheck(task["description"])
if len(errors) > 0:
- print('Spell errors:', ', '.join(errors))
- if not ENV_SKIP in os.environ:
+ print("Spell errors:", ", ".join(errors))
+ if ENV_SKIP not in os.environ:
sys.exit(1)
print(task.export_data())