Esempio n. 1
0
 def get(self, **kw):
     helper = RequestHelper(self)
     message = self.request.get("q", None)
     if not message:
         helper.error(400, "q must be provided")
         return
     message = urllib.unquote(message)
     try:
         sources, response = Mixer(new_speaker()).mix_response(message)
         logging.debug("sources:%s, response:%s" % (sources, response))
         result = dict(response=response)
         helper.write_json(result)
     except DataException, ex:
         helper.error(503, Exceptions.format(ex))
         logging.error(ex)
Esempio n. 2
0
 def get(self, **kw):
     helper = RequestHelper(self)
     message = self.request.get("q", None)
     if not message:
         helper.error(400, "q must be provided")
         return
     message = urllib.unquote(message)
     try:
         sources, response = Mixer(new_speaker()).mix_response(message)
         logging.debug("sources:%s, response:%s" % (sources, response))
         result = dict(response=response)
         helper.write_json(result)
     except DataException, ex:
         helper.error(503, Exceptions.format(ex))
         logging.error(ex)
Esempio n. 3
0
    def get(self, source_name, **kw):
        helper = RequestHelper(self)

        try:
            speaker_name = self.request.get("s", None)
            if speaker_name:
                speaker = new_speaker(speaker_name)[1]
                mixer = Mixer.new(speaker)
            else:
                speaker_name, speaker = new_random_speaker()
                logging.debug("speaker: %s" % str(speaker))
                mixer = Mixer(speaker)

            # direct message
            message = self.request.get("q", None)
            if message:
                message = urllib.unquote(message)
                sources, content = mixer.mix_response(message)
            else:
                if not source_name:
                    sources, content = mixer.mix_random_limit_sources(
                        2, degrade=True)
                else:
                    source_name = urllib.unquote(source_name)
                    logging.debug("get source_name: %s" % source_name)
                    if ";" in source_name:
                        # multiple sources
                        sources_split = set(source_name.split(";"))
                        sources, content = mixer.mix_sources(*sources_split)
                    else:
                        # single source
                        sources, content = mixer.mix_sources(source_name)
            logging.debug("sources: %s" % str(sources))
            source_hash_list = [s.name for s in sources]
            mix_hash = {
                "sources": source_hash_list,
                "speaker": {
                    "name": speaker_name,
                    "id": hash(speaker),
                    "details": str(speaker)
                },
                "body": content
            }
            helper.write_json(mix_hash)
        except NotFoundException, ex:
            helper.error(404, Exceptions.format(ex))
            logging.error(ex)
Esempio n. 4
0
    def get(self, source_name, **kw):
        helper = RequestHelper(self)

        try:
            speaker_name = self.request.get("s", None)
            if speaker_name:
                speaker = new_speaker(speaker_name)[1]
                mixer = Mixer.new(speaker)
            else:
                speaker_name, speaker = new_random_speaker()
                logging.debug("speaker: %s" % str(speaker))
                mixer = Mixer(speaker)
        
            # direct message
            message = self.request.get("q", None)
            if message:
                message = urllib.unquote(message)
                sources, content = mixer.mix_response(message)
            else:
                if not source_name:
                    sources, content = mixer.mix_random_limit_sources(2, degrade=True)
                else:
                    source_name = urllib.unquote(source_name)
                    logging.debug("get source_name: %s" % source_name)
                    if ";" in source_name:
                        # multiple sources
                        sources_split = set(source_name.split(";"))
                        sources, content = mixer.mix_sources(*sources_split)
                    else:
                        # single source
                        sources, content = mixer.mix_sources(source_name)
            logging.debug("sources: %s" % str(sources))
            source_hash_list = [s.name for s in sources]
            mix_hash = {"sources": source_hash_list,
                "speaker": {"name": speaker_name, "id": hash(speaker), "details": str(speaker)},
                "body": content}
            helper.write_json(mix_hash)
        except NotFoundException, ex:
            helper.error(404, Exceptions.format(ex))
            logging.error(ex)