-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpystatus.py
executable file
·82 lines (65 loc) · 2.41 KB
/
pystatus.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import json
import subprocess
import os
if sys.version_info[0] == 2:
reload(sys)
sys.setdefaultencoding('utf8')
dir_path=os.path.dirname(os.path.realpath(__file__))
def get_status():
spotify_read = subprocess.check_output("%s/getInfo.sh status" % dir_path, shell=True)
spotify_status=spotify_read.decode('utf-8')
return spotify_status
#sys.stdout.write(spotify_status)
def get_artist():
spotify_read = subprocess.check_output("%s/getInfo.sh artist" % dir_path, shell=True)
spotify_artist=spotify_read.decode('utf-8')
return spotify_artist[:-1]
#sys.stdout.write(spotify_artist)
def get_song():
spotify_read = subprocess.check_output("%s/getInfo.sh song" % dir_path, shell=True)
spotify_song=spotify_read.decode('utf-8')
return spotify_song[:-1]
#sys.stdout.write(spotify_song)
def read_line():
""" Interrupted respecting reader for stdin. """
# try reading a line, removing any extra whitespace
try:
line = sys.stdin.readline().strip()
# i3status sends EOF, or an empty line
if not line:
sys.exit(3)
return line
# exit on ctrl-c
except KeyboardInterrupt:
sys.exit()
def print_line(message):
""" Non-buffered printing to stdout. """
sys.stdout.write(message + '\n')
sys.stdout.flush()
def get_governor():
with open('/sys/devices/platform/i5k_amb.0/temp4_input') as fp:
return fp.readlines()[0].strip()
if __name__ == '__main__':
# Skip the first line which contains the version header.
print_line(read_line())
# The second line contains the start of the infinite array.
print_line(read_line())
while True:
line, prefix = read_line(), ''
# ignore comma at start of lines
if line.startswith(','):
line, prefix = line[1:], ','
if get_status() in ['Playing\n']:
j = json.loads(line)
# insert information into the start of the json, but could be anywhere
# CHANGE THIS LINE TO INSERT SOMETHING ELSE
j.insert(0, {'color' : '#9ec600', 'full_text' : ' %s - %s' % (get_artist(), get_song()) , 'name' : 'spotify'})
# and echo back new encoded json
print_line(prefix+json.dumps(j))
else:
j = json.loads(line)
print_line(prefix+json.dumps(j))
#print_line(json.dumps(j))