-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorg.py
More file actions
executable file
·36 lines (24 loc) · 767 Bytes
/
org.py
File metadata and controls
executable file
·36 lines (24 loc) · 767 Bytes
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
#!/usr/bin/env python3
from datetime import datetime
import re
from kython.org import date2org
from config import ORG_FILE_PATH
from main import get_new_tasks, mark_completed # TODO move to common?
def as_org(task) -> str:
id_, name, notes = task
name = re.sub(r'\s', ' ', name)
dt = datetime.now()
res = f"* TODO {name}\n SCHEDULED: <{date2org(dt)}>\n" + "\n".join(notes)
return res
def main():
tasks = get_new_tasks()
orgs = [as_org(t) for t in tasks]
ss = '\n\n'.join(orgs) + '\n\n'
# https://stackoverflow.com/a/13232181 should be atomic?
import io
with io.open(ORG_FILE_PATH, 'a') as fo:
fo.write(ss)
for date, _, _ in tasks:
mark_completed(date)
if __name__ == '__main__':
main()