-
Notifications
You must be signed in to change notification settings - Fork 0
/
org.albert.extension.external.notmuch.py
executable file
·96 lines (76 loc) · 2.14 KB
/
org.albert.extension.external.notmuch.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python3
import os
import sys
import json
import subprocess
import logging
logfile = os.path.expanduser('~/bk.log')
logging.basicConfig(filename=logfile, level=logging.DEBUG)
albert_op = os.environ.get("ALBERT_OP")
trigger = "nm "
if albert_op == "METADATA":
metadata = {
"iid": "org.albert.extension.external/v2.0",
"name": "Emails",
"version": "0.1",
"author": "Cinghio Pinghio",
"dependencies": ["notmuch"],
"trigger": trigger
}
print(json.dumps(metadata))
sys.exit(0)
elif albert_op == "NAME":
print("BuKu")
sys.exit(0)
elif albert_op == "INITIALIZE":
sys.exit(0)
elif albert_op == "FINALIZE":
sys.exit(0)
elif albert_op == "SETUPSESSION":
sys.exit(0)
elif albert_op == "SETUPSESSION":
sys.exit(0)
elif albert_op == "TEARDOWNSESSION":
sys.exit(0)
elif albert_op == "QUERY":
albert_query = os.environ.get("ALBERT_QUERY", '')
albert_query = albert_query[len(trigger):].strip()
logging.debug('query: ' + albert_query)
items = []
# if albert_query != '':
# command = ['buku', '--sreg', albert_query, '-j']
# else:
command = ['notmuch', 'count', 'tag:unread']
logging.debug('running ' + ' '.join(command))
proc = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
output, perr = proc.communicate()
output = output.decode().strip()
perr = perr.decode()
logging.debug('STDERR ' + perr)
logging.debug('STDOUT ' + output)
item = {
'id': 'notmuch',
'name': 'You have {} unread emails'.format(output),
'description': 'You have {} unread emails'.format(output),
'icon': "new-mail",
'actions': []
}
action = {
'command': 'notify-send',
'arguments': ['Happy', output],
'name': 'Notify'
}
item['actions'].append(action)
items.append(item)
res = {
'items': items[:]
}
print(json.dumps(res))
sys.exit(0)
elif albert_op == "COPYTOCLIPBOARD":
# clipboard.copy(sys.argv[1])
pass
sys.exit(0)