-
Notifications
You must be signed in to change notification settings - Fork 3
/
i3-exstatus.py
executable file
·66 lines (57 loc) · 1.59 KB
/
i3-exstatus.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
#!/usr/bin/env python
# Based on wrapper.py
import sys
import json
import socket
bat_color = {
'BAT' : '#ff0000',
'CHR' : '#ffff00',
'FUL' : '#ffffff',
'NCH' : '#ffffff',
}
def query_icedove():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('localhost', 3411))
reply = s.recv(8192)
s.close()
obj = json.loads(reply)
cnt = 0;
for accoutns in obj:
cnt = cnt + accoutns['unread']
if cnt == 0:
return ['No mail', '#ffffff']
else:
return ['New mail', '#ffff00']
except Exception as e:
return ['Mailer offline', '#ff0000']
def print_line(msg):
sys.stdout.write(msg + '\n')
sys.stdout.flush()
def read_line():
try:
line = sys.stdin.readline().strip();
if not line:
sys.exit(3);
return line
except KeyboardInterrupt:
sys.exit()
if __name__ == '__main__':
# {"version" : 1}
print_line(read_line())
# [
print_line(read_line())
while True:
line, prefix = read_line(), ''
if line.startswith(','):
line, prefix = line[1:], ','
j = json.loads(line)
mail = query_icedove()
j.insert(0, {'full_text' : mail[0], 'color' : mail[1], 'name' : 'icedove'})
for x in j:
if x['name'] == 'battery':
sig = x['full_text'][0:3]
x['color'] = bat_color[sig]
if x['full_text'][-1:] == ' ':
x['full_text'] = x['full_text'][:-1]
print_line(prefix + json.dumps(j))