コード例 #1
0
ファイル: sync_atom.py プロジェクト: adammck/shadow-poll
    def sync_atom(self, atom_url):
        response = urllib2.urlopen(atom_url)
        parser = IVRFeedParser()
        entries = parser.parse(response)

        voice_messages = []

        for entry in entries:
            response = urllib2.urlopen(entry.file_url)
            extension = entry.file_url.rsplit(".")[-1]
            file_name = str(uuid.uuid4())
            if len(extension) < 5:
                file_name = file_name + '.'+ extension
            file_name = os.path.join(self.media_dir, file_name)

            fout = open(file_name, 'w+b')
            fout.write(response.read())
            fout.close()

            voice_message = VoiceMessage()
            voice_message.fill(entry, file_name)
            voice_message.save()

            voice_messages.append(voice_message)

            entry.processed = True
            entry.save()
        return voice_messages
コード例 #2
0
    def test_get_child_image(self):
        voice_message = VoiceMessage(gender='m')
        self.assertEquals(voice_message.get_child_image(), "child_boy")

        voice_message = VoiceMessage(gender='f')
        self.assertEquals(voice_message.get_child_image(), "child_girl")

        voice_message = VoiceMessage(gender='')
        self.assertEquals(voice_message.get_child_image(), "child_no_identity")

        voice_message = VoiceMessage(gender='foo')
        self.assertEquals(voice_message.get_child_image(), "child_no_identity")

        voice_message = VoiceMessage()
        self.assertEquals(voice_message.get_child_image(), "child_no_identity")
コード例 #3
0
    def test_get_child_image(self):
        voice_message = VoiceMessage(female=False)
        self.assertEquals(voice_message.get_child_image(), "child_boy")

        voice_message = VoiceMessage(female=True)
        self.assertEquals(voice_message.get_child_image(), "child_girl")

        voice_message = VoiceMessage()
        self.assertEquals(voice_message.get_child_image(), "child_no_identity")