#!/usr/bin/env python #import pprint import json import ESL import os import redis r = redis.Redis(host='localhost', port=6379, db=0) headers = {'Content-Type': 'application/json', 'Accept-Charset': 'UTF-8'} #pp = pprint.PrettyPrinter(indent=4) con = ESL.ESLconnection('127.0.0.1', '8021', 'ClueCon') if con.connected(): con.events('json', 'CHANNEL_STATE') while 1: e = con.recvEvent() if e: call = json.loads(e.serialize('json')) if call['Event-Name'] == 'CHANNEL_STATE': #pp.pprint(call) #print 'Channel-state: '+ call['Channel-State'] if 'Channel-Presence-ID' in call.keys(): #print 'Channel-Presence-ID: '+ call['Channel-Presence-ID'] if call['Channel-State'] == 'CS_INIT': r.incr(call['Channel-Presence-ID']) if (call['Channel-State'] == 'CS_HANGUP') and (r.get(call['Channel-Presence-ID']) > 0): r.decr(call['Channel-Presence-ID'])