#!/usr/bin/env python

import time
import optparse

import socket
import json

def jsonFormatter(json, depth=0):

  for key in json.keys():
    result = "  " * depth + key
    if isinstance(json[key], dict):
      print result
      jsonFormatter(json[key], depth + 1)
    else:
      print result + ': ' + str(json[key])

parser = optparse.OptionParser()

parser.add_option("--mode", dest="mode", default='info',
                  help="select status mode [info, activity]", type="string")

(options, args) = parser.parse_args()

try:
  s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  s.connect("/tmp/.blitzortung-tracker")

  command = "get" + options.mode[0].upper() + options.mode[1:]

  s.send(json.dumps({'cmd':command}))
  jsonObject = json.loads(s.recv(10240))
  jsonFormatter(jsonObject)
  s.close()
except socket.error:
  print "no connection"

