single_command.py 980 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python
  2. import string
  3. import sys
  4. from optparse import OptionParser
  5. from ESL import *
  6. def main(argv):
  7. try:
  8. parser = OptionParser()
  9. parser.add_option("-a", "--auth", dest="auth", default="ClueCon",
  10. help="ESL password")
  11. parser.add_option("-s", "--server", dest="server", default="127.0.0.1",
  12. help="FreeSWITCH server IP address")
  13. parser.add_option("-p", "--port", dest="port", default="8021",
  14. help="FreeSWITCH server event socket port")
  15. parser.add_option("-c", "--command", dest="command",
  16. help="command to run, surround mutli word commands in \"\'s")
  17. (options, args) = parser.parse_args()
  18. con = ESLconnection(options.server, options.port, options.auth)
  19. #are we connected?
  20. if con.connected():
  21. #run command
  22. e = con.api(options.command)
  23. print e.getBody()
  24. else:
  25. print "Not Connected"
  26. sys.exit(2)
  27. except:
  28. print parser.get_usage()
  29. if __name__ == "__main__":
  30. main(sys.argv[1:])