Esempio n. 1
0
    def _get_podcasts(self, *args, **options):

        max_podcasts = options.get('max')

        if options.get('toplist'):
            yield (p.url for p in self.get_toplist(max_podcasts))

        if options.get('new'):
            podcasts = list(podcasts_need_update(limit=max_podcasts))
            random.shuffle(podcasts)
            yield (p.url for p in podcasts)

        if options.get('random'):
            # no need to pass "max" to random_podcasts, it uses chunked queries
            podcasts = random_podcasts()
            yield (p.url for p in individual_podcasts(podcasts))

        if options.get('next'):
            podcasts = podcasts_by_next_update(limit=max_podcasts)
            yield (p.url for p in individual_podcasts(podcasts))


        if args:
            yield args

        if not args and not options.get('toplist') and not options.get('new') \
                    and not options.get('random')  and not options.get('next'):
            podcasts = podcasts_by_last_update(limit=max_podcasts)
            yield (p.url for p in podcasts_by_last_update())
Esempio n. 2
0
def get_random_picks(languages=None):
    """ Returns random podcasts for the given language """

    languages = languages or ['']

    # get one iterator for each language
    rand_iters = [random_podcasts(lang) for lang in languages]

    # cycle through them, removing those that don't yield any more results
    while rand_iters:
        rand_iter = rand_iters.pop(0)

        try:
            podcast = next(rand_iter)
            rand_iters.append(rand_iter)
            yield podcast

        except StopIteration:
            # don't re-add rand_iter
            pass
Esempio n. 3
0
File: views.py Progetto: fk-lx/mygpo
 def get_random_podcast(self):
     random_podcast = next(random_podcasts(), None)
     if random_podcast:
         yield random_podcast.get_podcast()