This repository has been archived by the owner on Nov 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathimport.py
executable file
·59 lines (44 loc) · 1.54 KB
/
import.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
import sys
import json
from datetime import datetime
if len(sys.argv) != 3:
raise Exception('args missing or invalid')
if not sys.argv[1]:
raise Exception('provider missing')
if not sys.argv[2]:
raise Exception('file missing')
if sys.argv[1] == 'taskwarrior':
tasks = {}
database_in = open(sys.argv[2], 'r')
database_out = open('.database', 'w')
def parse_due(raw_due):
return raw_due if not raw_due else datetime.strptime(raw_due, '%Y%m%dT%H%M%SZ').strftime('%s')
def parse_status(status):
return 1 if status == 'completed' or status == 'deleted' else 0
for line in database_in.read().split('\n'):
try:
task = json.loads(line)
if 'tags' not in task.keys():
task['tags'] = []
if 'due' not in task.keys():
task['due'] = ''
tasks[task['uuid']] = {
'desc': task['description'],
'tags': task['tags'],
'due': parse_due(task['due']),
'index': parse_due(task['entry']),
'start': [],
'stop': [],
'active': 0,
'done': parse_status(task['status']),
}
except:
continue
database_out.write('[]\n0\n')
for index, task in enumerate(tasks.values()):
task['id'] = index + 1
task['index'] = -int(str(task['id']) + task['index'])
database_out.write(json.dumps(task) + '\n')
database_in.close()
database_out.close()