Example #1
0
def clear_cache():
    tmppath = '/'.join(sys.argv[1].split('/')[:-1]) + '/'
    tmpfiles = os.listdir(tmppath)
    cache = [
        tmppath + '/' + i for i in tmpfiles
        if os.stat(tmppath + '/' + i).st_atime +
        60 * 60 * 24 * 2 < time.time()
    ]
    for i in cache:
        os.remove(i)
    agi.verbose('Cache cleared!')
Example #2
0
 def handle(self):
     try:
         agi=asterisk.agi.AGI(stdin=self.rfile, stdout=self.wfile, stderr=sys.stderr)
         agi.verbose("pyst2: FastAGI on: {}:{}".format(HOST, PORT))
     except TypeError as e:
         sys.stderr.write('Unable to connect to agi://{} {}\n'.format(self.client_address[0], str(e)))
     except SocketServer.socket.timeout as e:
         sys.stderr.write('Timeout receiving data from {}\n'.format(self.client_address))
     except SocketServer.socket.error as e:
         sys.stderr.write('Could not open the socket. Is someting else listening on this port?\n')
     except Exception as e:
         sys.stderr.write('An unknown error: {}\n'.format(str(e)))
Example #3
0
 def handle(self):
     try:
         agi = asterisk.agi.AGI(stdin=self.rfile, stdout=self.wfile)
         agi.verbose("pyst2: FastAGI on: {}:{}".format(HOST, PORT))
     except TypeError:
         logger.exception('Unable to connect to agi://{}'.format(
             self.client_address[0]))
     except SocketServer.socket.timeout:
         logger.exception('Timeout receiving data from {}'.format(
             self.client_address))
     except SocketServer.socket.error:
         logger.exception('Could not open the socket. Is someting else '
                          'listening on this port?')
     except Exception:
         logger.exception('An unknown error')
Example #4
0
 def handle(self):
     try:
         agi = asterisk.agi.AGI(stdin=self.rfile,
                                stdout=self.wfile,
                                stderr=sys.stderr)
         agi.verbose("pyst2: FastAGI on: {}:{}".format(HOST, PORT))
     except TypeError as e:
         sys.stderr.write('Unable to connect to agi://{} {}\n'.format(
             self.client_address[0], str(e)))
     except SocketServer.socket.timeout as e:
         sys.stderr.write('Timeout receiving data from {}\n'.format(
             self.client_address))
     except SocketServer.socket.error as e:
         sys.stderr.write(
             'Could not open the socket. Is someting else listening on this port?\n'
         )
     except Exception as e:
         sys.stderr.write('An unknown error: {}\n'.format(str(e)))
Example #5
0
#!/usr/bin/python
'''Example Application to post a tweet from AGI'''

import tweepy
import asterisk.agi
import sys

# Your Keys Here:
consumerKey = ''
consumerSecret = ''
oauthToken = ''
oauthTokenSecret = ''

agi = asterisk.agi.AGI()
status = agi.get_variable('status')[1:-1]

try:
   auth = tweepy.OAuthHandler(consumerKey, consumerSecret)
   auth.set_access_token(oauthToken, oauthTokenSecret)
   api = tweepy.API(auth)
   tweet = api.update_status(status)
   success = "SUCCESS! https://twitter.com/%s/status/%s" % (tweet.user.screen_name, tweet.id)
   agi.verbose(success)
   agi.set_variable('tweet_success','1')
except tweepy.TweepError as e:
   agi.verbose('Twitter encountered an error: %s' % e.reason[1:-1])
   agi.set_variable('tweet_success','0')

sys.exit(0)
Example #6
0
        tmppath + '/' + i for i in tmpfiles
        if os.stat(tmppath + '/' + i).st_atime +
        60 * 60 * 24 * 2 < time.time()
    ]
    for i in cache:
        os.remove(i)
    agi.verbose('Cache cleared!')


clear_cache()

if sys.argv[2].replace(' ', '') == "1":
    try:
        f1 = get_file()
        #agi.set_variable('audio', '/var/lib/asterisk/agi-bin/default_speech/wait_pls')
        agi.verbose('Start recognise wav')
        result = speech_to_text(f1)
        agi.verbose('File :%s | Recognised as : %s' % (f1, result))
        dialog_log(f1, result)
        agi.verbose('Start geting Description...')
        description = get_descripton(result)
        result = text_replace(result)
        agi.verbose('Description geted -> %s' % description)
        description = text_replace(description)
        f2 = set_file()
        text = 'Вы сказали '+result+' -'*5 + 'Ваша проблема классифицирована как ' + ' -'*3 + description + ' -'*10 + \
        'Вы - хаат+ите оставить - заявку? - '
        #            'А теперь давайте поиграем - - - Вы - хоот+ите купить - слона?'
        #               ' С вас печеньки моему разработчику - - - Михаилу!'
        text_to_speech(text, f2 + '.wav')
        dialog_log(f2, text)