This commit is contained in:
olari
2021-07-05 22:09:53 +03:00
parent 468701b220
commit 3ef24d2bfe

View File

@@ -1,6 +1,6 @@
from copy import deepcopy from copy import deepcopy
from datetime import datetime, timedelta from datetime import datetime, timedelta
from functools import reduce, partial from functools import cache, reduce, partial
from pathlib import Path from pathlib import Path
from shutil import copyfile, rmtree from shutil import copyfile, rmtree
from subprocess import run from subprocess import run
@@ -23,7 +23,7 @@ def remove_chars(text, chars):
return ''.join([c for c in text if c not in chars]) return ''.join([c for c in text if c not in chars])
def get_words(text): def get_words(text):
return remove_chars(text, '.,-:;').lower().split() return remove_chars(text, '.,-:;/').lower().split()
def nth_or_default(n, l, default): def nth_or_default(n, l, default):
return l[n] if n < len(l) else default return l[n] if n < len(l) else default
@@ -231,6 +231,7 @@ def init_hacky_hackery(journal):
global _global_do_not_use global _global_do_not_use
_global_do_not_use = journal _global_do_not_use = journal
@cache
def get_foods_file(): def get_foods_file():
return parse_foods_file(_global_do_not_use['files']['foods']) return parse_foods_file(_global_do_not_use['files']['foods'])
@@ -1026,6 +1027,12 @@ def handle_tasks(args):
save_journal(edit_entries_by_predicate(load_journal(), predicate)) save_journal(edit_entries_by_predicate(load_journal(), predicate))
def handle_profile(args):
import cProfile
cProfile.run("export_journal(load_journal(), Path(mkdtemp()))", sort='cumtime')
### MAIN ### MAIN
def main(): def main():
@@ -1046,7 +1053,8 @@ def main():
'summary': handle_summary, 'summary': handle_summary,
'backup': handle_backup, 'backup': handle_backup,
'search': handle_search, 'search': handle_search,
'tasks': handle_tasks 'tasks': handle_tasks,
'profile': handle_profile,
} }
handler = command_handlers.get(command, handle_invalid) handler = command_handlers.get(command, handle_invalid)