#!/usr/bin/env python
import SimpleHTTPServer
import SocketServer
import pdb
import time
import re
import collections
import os
import subprocess
import datetime
import calendar
import json

reporting_time_seconds = 4*7*24*60*60

def utc_now():
  return calendar.timegm(datetime.datetime.utcnow().utctimetuple())

def dict_for(id, field, value):
  return {
    'data': {
      'id': id,
      field: value,
      'updatedAt': utc_now(),
    }
  }

def get_data():
  since_time = time.strftime("%d%b%y", time.localtime(calendar.timegm(
      time.localtime()) - reporting_time_seconds))
  subprocess.check_output(("""gtacl -c "\$system.system.showlog """
      """ \$system.zssh.sshlog2 * \\"{} 00:01:00\\"" > /tmp/log """).
      format(since_time), shell=True)
  user_count = int(subprocess.check_output("grep successful /tmp/log | wc -l", 
      shell=True).split()[0])
  u = subprocess.check_output("grep 'password verification successful "  
      "for user' /tmp/log", shell=True)
  # ^password verification successful for user 'username'$
  users = map(lambda v: re.search("'([^']+)'", v).group(1), u.splitlines()) 
  top_users = collections.Counter(users).most_common(5)
  return json.dumps([
    dict_for("ssh-sessions", "value", user_count), 
    dict_for("top-users", "items", 
    [{"label": u[0], "value": u[1]} for u in top_users])
  ])

class MyRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
  def do_GET(self):
    if self.path == '/data':
      self.send_response(200)
      self.send_header('Content-Type', 'application/json')
      self.end_headers()
      self.wfile.write(get_data())
      return
    return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)

Handler = MyRequestHandler
server = SocketServer.TCPServer(('0.0.0.0', 8080), Handler)
server.serve_forever()

@@ -1,10 +1,11 @@
 #!
+ 
 /usr/bin
@@ -160,24 +160,8 @@
 ime%0A
-import calendar%0A
 impo
@@ -212,92 +212,8 @@
 60%0A%0A
-def utc_now():%0A  return calendar.timegm(datetime.datetime.utcnow().utctimetuple())%0A%0A
 def 
@@ -324,15 +324,17 @@
 t': 
-utc_now
+time.time
 (),%0A
@@ -418,50 +418,28 @@
 ime(
-calendar.timegm(%0A      time.localtime()) -
+time.time() - %0A     
  rep
@@ -748,17 +748,24 @@
 )%5B0%5D)%0A  
-u
+log_blob
  = subpr
@@ -986,17 +986,31 @@
 oup(1), 
-u
+%0A      log_blob
 .splitli

Remove dependence on calendar.