Beispiel #1
0
def get_voicemail():
    spool_path = os.path.join(ASTERISK_SPOOLPATH, 'voicemail', ASTERISK_VM_CONTEXT, ASTERISK_EXTENSION, 'INBOX')
    messages = []
    for mail in glob.glob(os.path.join(spool_path, '*.txt')):
        config = configparser.ConfigParser()
        config.read(mail)
        wav_file = '.'.join((os.path.basename(mail).split('.')[0], 'wav'))
        messages.append({'duration': config.getint('message', 'duration'),
                         'from': config.get('message', 'callerid'),
                         'date': datetime.datetime.fromtimestamp(config.getint('message', 'origtime')),
                         'file': os.path.join(spool_path, wav_file)})
    return messages
Beispiel #2
0
    def download(self, file_id):
        """Downloads a file and returns its data.

        :param file_id: Resource by file_id.
        :type file_id: int
        :return: Tuple containing file_path and actual binary data.
        :rtype: tuple
        """
        cmd = GetFile(file_id=file_id)
        file = yield from self._execute_command(cmd)
        logger.debug('Downloading file {path}'.format(path=file.file_path))
        r = yield from aiohttp.get(FILE_URL.format(token=config.get('bot')['token'],
                                                   path=file.file_path))

        data = yield from r.read()
        return file.file_path, data
Beispiel #3
0
    def _execute_command(self, command, headers=None):
        action = {'get': aiohttp.get,
                  'post': aiohttp.post}.get(command.method)
        if logger.isEnabledFor(logging.DEBUG):
            logger.debug("Executing command {command} params={params} data={data}".format(command=command.command,
                                                                                          params=command.get_params(),
                                                                                          data=command.get_data()))
        r = yield from action(API_URL.format(token=config.get('bot')['token'], method=command.command),
                              params=command.get_params(),
                              data=command.get_data(),
                              headers=headers)

        resp = yield from r.json()
        if not resp['ok']:
            logger.debug(resp)
            raise Exception('Error while processing Request')
        return command.parse_result(resp['result'])