3
"""Helioviewer.org Status Information Conky Script
5
This script queries Helioviewer.org to find how far behind data is for
6
each instrument, and generates a small conky snippet to display the
7
results. This can be used with the conky execp/execpi commands, e.g.:
9
The net result should be similar to the information obtained when visiting
10
the Helioviewer.org status page at http://www.helioviewer.org/status.
15
${voffset 4}${execpi 5 ~/.conky/helioviewer_status.py}
18
from urllib2 import urlopen
21
# Conky formatting parameters'
22
# Better: allow user to specify as command-line arguments
23
CONKY_FONT = "DroidSansMono"
31
HV_QUERY_URL = "http://www.helioviewer.org/api/?action=getStatus"
42
# Query Helioviewer.org
43
response = urlopen(HV_QUERY_URL).read()
44
instruments = json.loads(response)
46
# Generate conky snippet
47
voffset = "${voffset %d}" % CONKY_VOFFSET
48
font = "${font %s:size=%0.1f}" % (CONKY_FONT, CONKY_FONT_SIZE)
49
color = "${color%d}" % CONKY_COLOR_NUM
50
alignc = "${alignc %d}" % CONKY_ALIGNC
52
# Iterate through instruments in sorted order
53
iterator = iter(sorted(instruments.iteritems()))
55
for inst, status in iterator:
56
# Ignore non-active datasets (30 days or more behind real-time)
57
if status['secondsBehind'] > (30 * 24 * 60 * 60):
61
icon = "${offset 3}${font Webdings:size=%0.1f}${color %s}n${font} " % (CONKY_FONT_SIZE * 0.85, colors[status['level']])
64
if status['secondsBehind'] < (60 * 60):
65
time = "%d minutes" % (status['secondsBehind'] / 60)
66
elif status['secondsBehind'] < (24 * 60 * 60):
67
time = "%0.1f hours" % (status['secondsBehind'] / (60 * 60.))
69
time = "%0.1f days" % (status['secondsBehind'] / (24 * 60 * 60.))
72
print (voffset + icon + font + color + alignc + inst + "${alignr}" + time + "${font}")
74
if __name__ == '__main__':