From Mature Mousedeer, 4 Years ago, written in Python.
- go back
Embed
Viewing differences between and Untitled
  1. #!/usr/bin/env python
  2. #import pprint
  3. import json
  4. import ESL
  5. import os
  6.  
  7. import redis
  8. r = redis.Redis(host='localhost', port=6379, db=0)
  9.  
  10. headers = {'Content-Type': 'application/json', 'Accept-Charset': 'UTF-8'}
  11.  
  12. #pp = pprint.PrettyPrinter(indent=4)
  13.  
  14. con = ESL.ESLconnection('127.0.0.1', '8021', 'ClueCon')
  15. if con.connected():
  16.     con.events('json', 'CHANNEL_STATE')
  17.     while 1:
  18.         e = con.recvEvent()
  19.         if e:
  20.             call = json.loads(e.serialize('json'))
  21.             if call['Event-Name'] == 'CHANNEL_STATE':
  22.               #pp.pprint(call)
  23.               #print 'Channel-state: '+ call['Channel-State']
  24.               if 'Channel-Presence-ID' in call.keys():
  25.                 #print 'Channel-Presence-ID: '+ call['Channel-Presence-ID']
  26.                 if call['Channel-State'] == 'CS_INIT':
  27.                   r.incr(call['Channel-Presence-ID'])
  28.                 if (call['Channel-State'] == 'CS_HANGUP') and (r.get(call['Channel-Presence-ID']) > 0):
  29.                   r.decr(call['Channel-Presence-ID'])