Exemple #1
0
def main():
    with open('thebugle.json') as f:
        episodes = json.load(f)

    p = Podcast(
        name="TimesOnLine Bugle Archive",
        description="Old Bugle episodes, podcast feed",
        website="https://www.thebuglepodcast.com/",
        explicit=False,
    )

    for episode in episodes:
        ep = p.add_episode(
            Episode(title=f"{episode['id']}: {episode['title']}"))
        ep.media = Media.create_from_server_response(
            f"{MEDIA_BASE_URL}/{episode['file']}")

        ep.media.fetch_duration()

        date = episode['date'].split('-')
        ep.publication_date = datetime(int(date[0]),
                                       int(date[1]),
                                       int(date[2]),
                                       0,
                                       0,
                                       0,
                                       tzinfo=pytz.utc)

    print(p.rss_str())
Exemple #2
0
    def test_createFromServerResponse(self):
        # Mock our own requests object
        url = self.url
        type = self.type
        size = self.size

        class MyLittleRequests(object):
            @staticmethod
            def head(*args, **kwargs):
                assert args[0] == url
                assert kwargs['allow_redirects'] == True
                assert 'timeout' in kwargs

                class MyLittleResponse(object):
                    headers = {
                        'Content-Type': type,
                        'Content-Length': size,
                    }

                    @staticmethod
                    def raise_for_status():
                        pass

                return MyLittleResponse

        m = Media.create_from_server_response(url,
                                              duration=self.duration,
                                              requests_=MyLittleRequests)
        self.assertEqual(m.url, url)
        self.assertEqual(m.size, size)
        self.assertEqual(m.type, type)
        self.assertEqual(m.duration, self.duration)
Exemple #3
0
    def test_createFromServerResponse(self):
        # Mock our own requests object
        url = self.url
        type = self.type
        size = self.size

        class MyLittleRequests(object):
            @staticmethod
            def head(*args, **kwargs):
                assert args[0] == url
                assert kwargs['allow_redirects'] == True
                assert 'timeout' in kwargs

                class MyLittleResponse(object):
                    headers = {
                        'Content-Type': type,
                        'Content-Length': size,
                    }

                    @staticmethod
                    def raise_for_status():
                        pass

                return MyLittleResponse

        m = Media.create_from_server_response(url, duration=self.duration,
                                              requests_=MyLittleRequests)
        self.assertEqual(m.url, url)
        self.assertEqual(m.size, size)
        self.assertEqual(m.type, type)
        self.assertEqual(m.duration, self.duration)