forked from mk1123/timebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
34 lines (29 loc) · 994 Bytes
/
tasks.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
import os
import re
import things
from dataclasses import dataclass
@dataclass
class Task:
minutes: int = 0
title: str = ''
url: str = ''
def _get_today_tasks():
DB = os.path.expanduser(
"~/Library/Group Containers/JLMPQHK86H.com.culturedcode.ThingsMac/Things Database.thingsdatabase/main.sqlite"
)
mytasks = []
tasks = things.today(filepath=DB)
for task in tasks:
duration_tag = next((tag for tag in task.get('tags', []) if re.match(r"[0-9]+min", tag)), '')
mytasks.append((duration_tag, task['title'], things.link(task['uuid'])))
return mytasks
def get_things_today_tasks():
list_of_tasks = _get_today_tasks()
processed_tasks = {}
for task_tuple in list_of_tasks:
processed_tasks[task_tuple[1]] = Task(
minutes = int(task_tuple[0][:-3]) if task_tuple[0][-3:] == "min" else 0,
title = task_tuple[1],
url = task_tuple[2]
)
return processed_tasks