~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to extra/conky/helioviewer_status.py

  • Committer: Keith Hughitt
  • Date: 2012-07-26 21:26:16 UTC
  • Revision ID: keith.hughitt@nasa.gov-20120726212616-hos4e9yyun3ebvlq
Added conky script to display Helioviewer.org status information

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#-*- coding:utf-8 -*-
 
3
"""Helioviewer.org Status Information Conky Script
 
4
 
 
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.:
 
8
 
 
9
 
 
10
 
 
11
The net result should be similar to the information obtained when visiting
 
12
the Helioviewer.org status page at http://www.helioviewer.org/status.
 
13
"""
 
14
from urllib2 import urlopen
 
15
import json
 
16
 
 
17
# Conky formatting parameters
 
18
CONKY_FONT = "DroidSansMono"
 
19
CONKY_FONT_SIZE = 7.6
 
20
CONKY_COLOR_NUM = 3
 
21
CONKY_VOFFSET = 0
 
22
CONKY_ALIGNC = 60
 
23
 
 
24
def main():
 
25
    """Main"""
 
26
    HV_QUERY_URL = "http://www.helioviewer.org/api/?action=getStatus"
 
27
 
 
28
    # Query Helioviewer.org
 
29
    response = urlopen(HV_QUERY_URL).read()
 
30
    instruments = json.loads(response)
 
31
 
 
32
    # Sort results by instrument
 
33
 
 
34
    
 
35
    # Generate conky snippet
 
36
    voffset = "${voffset %d}" % CONKY_VOFFSET
 
37
    font = "${font %s:size=%0.1f}" % (CONKY_FONT, CONKY_FONT_SIZE)
 
38
    color = "${color%d}" % CONKY_COLOR_NUM
 
39
    alignc = "${alignc %d}" % CONKY_ALIGNC
 
40
 
 
41
    for inst, status in instruments.items():
 
42
        # Ignore non-active datasets (30 days or more behind real-time)
 
43
        if status['secondsBehind'] > (30 * 24 * 60 * 60):
 
44
            continue
 
45
 
 
46
        #icon = "${font WingDings}${color green}n${font}"
 
47
        # Icon and time string
 
48
        icon = "${color green}O"
 
49
        time = "%d Minutes Behind" % (status['secondsBehind'] / 60)
 
50
 
 
51
        # Print snippet
 
52
        print (voffset + icon + font + color + alignc + inst + ": " +
 
53
               str(status['level']) + " - " + time  + "${font}")
 
54
 
 
55
if __name__ == '__main__':
 
56
    main()
 
57