Esempio n. 1
0
File: tags.py Progetto: Mic92/mygpo
    def for_podcast(cls, podcast):
        """ all tags for the podcast, in decreasing order of importance """

        res = Podcast.view('tags/by_podcast',
                startkey    = [podcast.get_id(), None],
                endkey      = [podcast.get_id(), {}],
                reduce      = True,
                group       = True,
                group_level = 2,
                stale       = 'update_after',
            )

        tags = Counter(dict((x['key'][1], x['value']) for x in res))

        res = Podcast.view('usertags/by_podcast',
                startkey    = [podcast.get_id(), None],
                endkey      = [podcast.get_id(), {}],
                reduce      = True,
                group       = True,
                group_level = 2,
            )

        tags.update(Counter(dict( (x['key'][1], x['value']) for x in res)))

        get_tag = itemgetter(0)
        return map(get_tag, tags.most_common())
Esempio n. 2
0
File: slugs.py Progetto: Mic92/mygpo
    def _get_existing_slugs(self):
        from mygpo.core.models import Podcast

        res = Podcast.view(
            "podcasts/by_slug", startkey=[self.base_slug, None], endkey=[self.base_slug + "ZZZZZ", None], wrap_doc=False
        )
        return [r["key"][0] for r in res]
Esempio n. 3
0
def podcast_slugs(base_slug):
    res = Podcast.view('podcasts/by_slug',
            startkey = [base_slug, None],
            endkey   = [base_slug + 'ZZZZZ', None],
            wrap_doc = False,
        )
    return [r['key'][0] for r in res]
Esempio n. 4
0
def podcasts_by_last_update(limit=100):
    res = Podcast.view('podcasts/by_last_update',
            include_docs = True,
            stale        = 'update_after',
            wrap_doc     = False,
            limit        = limit,
        )

    # TODO: this method is only used for retrieving podcasts to update;
    #       should we really send 'incomplete_obj' signals here?

    return map(_wrap_podcast_group_key1, res)
Esempio n. 5
0
File: tags.py Progetto: Mic92/mygpo
    def for_user(cls, user, podcast_id=None):
        """ mapping of all podcasts tagged by the user with a list of tags """

        res = Podcast.view('tags/by_user',
                startkey = [user._id, podcast_id],
                endkey   = [user._id, podcast_id or {}]
            )

        tags = defaultdict(list)
        for r in res:
            tags[r['key'][1]].append(r['value'])
        return tags
Esempio n. 6
0
def podcasts_by_next_update(limit=100):
    """ Returns the podcasts that are due for an update next """

    res = Podcast.view('podcasts/by_next_update',
            include_docs = True,
            stale        = 'update_after',
            limit        = limit,
            classes      = [Podcast, PodcastGroup],
        )

    # TODO: this method is only used for retrieving podcasts to update;
    #       should we really send 'incomplete_obj' signals here?

    return list(res)
Esempio n. 7
0
def podcast_duplicates_for_url(url):

    if not url:
        raise QueryParameterMissing('url')

    _view = 'podcasts/by_url'
    r = Podcast.view(_view,
            key          = url,
            classes      = [Podcast, PodcastGroup],
            include_docs = True,
        )

    for pg in r:
        yield pg.get_podcast_by_url(url)
Esempio n. 8
0
    def handle(self, *args, **options):

        silent = options.get('silent')

        # couchdbkit doesn't preserve microseconds
        started = datetime.utcnow().replace(microsecond=0)

        podcasts = Podcast.all_podcasts()
        total = Podcast.view('podcasts/by_oldid', limit=0).total_rows

        for n, podcast in enumerate(podcasts):
            subscriber_count = self.get_subscriber_count(podcast)
            self.update(podcast=podcast, started=started, subscriber_count=subscriber_count)

            if not silent:
                progress(n, total)
Esempio n. 9
0
def get_podcast_languages():
    """ Returns all 2-letter language codes that are used by podcasts.

    It filters obviously invalid strings, but does not check if any
    of these codes is contained in ISO 639. """

    from mygpo.web.utils import sanitize_language_codes

    res = Podcast.view('podcasts/by_language',
            group_level = 1,
            stale       = 'ok',
        )

    langs = [r['key'][0] for r in res]
    sane_lang = sanitize_language_codes(langs)
    sane_lang.sort()
    return sane_lang
Esempio n. 10
0
def get_flattr_podcasts(offset=0, limit=20):
    """ returns all podcasts that contain Flattr payment URLs """

    r = Podcast.view('podcasts/flattr',
            skip         = offset,
            limit        = limit,
            classes      = [Podcast, PodcastGroup],
            include_docs = True,
            reduce       = False,
        )

    podcasts = list(r)

    for podcast in podcasts:
        if podcast.needs_update:
            incomplete_obj.send_robust(sender=podcast)

    return podcasts
Esempio n. 11
0
def podcasts_by_id(ids):

    if ids is None:
        raise QueryParameterMissing('ids')

    if not ids:
        return []

    r = Podcast.view('podcasts/by_id',
            keys         = ids,
            include_docs = True,
            wrap_doc     = False
        )

    podcasts = map(_wrap_podcast_group, r)

    for podcast in podcasts:
        if podcast.needs_update:
            incomplete_obj.send_robust(sender=podcast)

    return podcasts
Esempio n. 12
0
def get_license_podcasts(offset=0, limit=20, license_url=None):
    """ returns a page of podcasts w/ license information """

    kwargs = {}
    if license_url:
        kwargs['key'] = license_url

    r = Podcast.view('podcasts/license',
            skip = offset,
            limit = limit,
            classes = [Podcast, PodcastGroup],
            include_docs = True,
            reduce = False,
            **kwargs
    )

    podcasts = list(r)

    for podcast in podcasts:
        if podcast.needs_update:
            incomplete_obj.send_robust(sender=podcast)

    return podcasts
Esempio n. 13
0
    def handle(self, *args, **options):

        get_podcast = itemgetter(0)

        max_related = options.get('max')

        podcasts = Podcast.all_podcasts()
        total = Podcast.view('podcasts/by_id', limit=0).total_rows

        for (n, podcast) in enumerate(podcasts):

            l = calc_similar_podcasts(podcast)[:max_related]

            related = map(get_podcast, l)

            @repeat_on_conflict(['podcast'])
            def _update(podcast, related):
                podcast.related_podcasts = related
                podcast.save()

            _update(podcast=podcast, related=related)

            progress(n+1, total)
Esempio n. 14
0
def random_podcasts(language='', chunk_size=5):
    """ Returns an iterator of random podcasts

    optionaly a language code can be specified. If given the podcasts will
    be restricted to this language. chunk_size determines how many podcasts
    will be fetched at once """

    while True:
        rnd = random()
        res = Podcast.view('podcasts/random',
                startkey     = [language, rnd],
                include_docs = True,
                limit        = chunk_size,
                stale        = 'ok',
                wrap_doc     = False,
            )

        if not res:
            break

        for r in res:
            # The view podcasts/random does not include incomplete podcasts,
            # so we don't need to send any 'incomplete_obj' signals here
            yield _wrap_pg(r)
Esempio n. 15
0
def podcast_count():
    return Podcast.view('podcasts/by_id',
            limit = 0,
            stale = 'update_after',
        ).total_rows