示例#1
0
文件: episode.py 项目: fk-lx/mygpo
def episodes_for_podcast_uncached(podcast, since=None, until={}, **kwargs):

    if not podcast:
        raise QueryParameterMissing('podcast')


    if kwargs.get('descending', False):
        since, until = until, since

    if isinstance(since, datetime):
        since = since.isoformat()

    if isinstance(until, datetime):
        until = until.isoformat()

    res = Episode.view('episodes/by_podcast',
            startkey     = [podcast.get_id(), since],
            endkey       = [podcast.get_id(), until],
            include_docs = True,
            reduce       = False,
            **kwargs
        )

    episodes = list(res)

    for episode in episodes:
        if episode.needs_update:
            incomplete_obj.send_robust(sender=episode)

    return episodes
示例#2
0
文件: podcast.py 项目: fk-lx/mygpo
def podcasts_groups_by_id(ids):
    """ gets podcast groups and top-level podcasts for the given ids """

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

    if not ids:
        return

    db = get_main_database()
    res = db.view('podcasts/podcasts_groups',
            keys         = ids,
            include_docs = True,
        )

    for r in res:
        obj = _wrap_pg(r)

        if not obj:
            yield None
            continue

        if obj.needs_update:
            incomplete_obj.send_robust(sender=obj)

        yield obj
示例#3
0
文件: podcast.py 项目: fk-lx/mygpo
def search(q, offset=0, num_results=20):

    if not q:
        return [], 0

    db = get_main_database()

    FIELDS = ['title', 'description']
    q = lucene_query(FIELDS, q)

    try:
        res = db.search('podcasts/search',
                wrapper      = search_wrapper,
                include_docs = True,
                limit        = num_results,
                stale        = 'update_after',
                skip         = offset,
                q            = q,
            )

        podcasts = list(res)

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

        return podcasts, res.total_rows

    except RequestFailed:
        return [], 0
示例#4
0
文件: episode.py 项目: fk-lx/mygpo
def episodes_for_slug(podcast_id, episode_slug):
    """ returns all episodes for the given slug

    this should normally only return one episode, but there might be multiple
    due to resolved replication conflicts, etc """

    if not podcast_id:
        raise QueryParameterMissing('podcast_id')

    if not episode_slug:
        raise QueryParameterMissing('episode_slug')

    r = Episode.view('episodes/by_slug',
            key          = [podcast_id, episode_slug],
            include_docs = True,
        )

    if not r:
        return []

    episodes = r.all()

    for episode in episodes:
        if episode.needs_update:
            incomplete_obj.send_robust(sender=episode)

    return episodes
示例#5
0
文件: podcast.py 项目: fk-lx/mygpo
def podcastgroup_by_id(group_id):

    if not group_id:
        raise QueryParameterMissing('group_id')

    pg = PodcastGroup.get(group_id)

    if pg.needs_update:
        incomplete_obj.send_robust(sender=pg)

    return pg
示例#6
0
文件: podcast.py 项目: fk-lx/mygpo
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
示例#7
0
文件: episode.py 项目: fk-lx/mygpo
def episodes_for_podcast_current(podcast, limit=None):

    if not podcast:
        raise QueryParameterMissing('podcast')

    res = Episode.view('episodes/by_podcast_current',
            startkey     = podcast.get_id(),
            endkey       = podcast.get_id(),
            include_docs = True,
            limit        = limit,
        )

    episodes = list(res)

    for episode in episodes:
        if episode.needs_update:
            incomplete_obj.send_robust(sender=episode)

    return episodes
示例#8
0
文件: podcast.py 项目: fk-lx/mygpo
def podcast_by_id_uncached(podcast_id, current_id=False):

    if not podcast_id:
        raise QueryParameterMissing('podcast_id')

    db = get_main_database()
    podcast = get_single_result(db, 'podcasts/by_id',
            key          = podcast_id,
            include_docs = True,
            wrapper      = _wrap_podcast_group,
        )

    if not podcast:
        return None

    if podcast.needs_update:
        incomplete_obj.send_robust(sender=podcast)

    return podcast
示例#9
0
文件: podcast.py 项目: fk-lx/mygpo
def podcastgroup_for_oldid(oldid):

    if not oldid:
        raise QueryParameterMissing('oldid')

    db = get_main_database()
    pg = get_single_result(db, 'podcasts/groups_by_oldid',
            key          = long(oldid),
            include_docs = True,
            schema       = PodcastGroup,
        )

    if not pg:
        return None

    if pg.needs_update:
        incomplete_obj.send_robust(sender=pg)

    return pg
示例#10
0
文件: podcast.py 项目: fk-lx/mygpo
def podcast_for_oldid(oldid):

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

    db = get_main_database()
    podcast = get_single_result(db, 'podcasts/by_oldid',
            key          = long(oldid),
            include_docs = True,
            wrapper      = _wrap_podcast_group_key1,
        )

    if not podcast:
        return None

    if podcast.needs_update:
        incomplete_obj.send_robust(sender=podcast)

    return podcast
示例#11
0
文件: episode.py 项目: fk-lx/mygpo
def episode_for_podcast_id_url(podcast_id, episode_url, create=False):

    if not podcast_id:
        raise QueryParameterMissing('podcast_id')

    if not episode_url:
        raise QueryParameterMissing('episode_url')


    key = u'episode-podcastid-%s-url-%s' % (
            sha1(podcast_id.encode('utf-8')).hexdigest(),
            sha1(episode_url.encode('utf-8')).hexdigest())

#   Disabled as cache invalidation is not working properly
#   episode = cache.get(key)
#   if episode:
#       return episode

    db = get_main_database()
    episode = get_single_result(db, 'episodes/by_podcast_url',
            key          = [podcast_id, episode_url],
            include_docs = True,
            reduce       = False,
            schema       = Episode,
        )

    if episode:
        if episode.needs_update:
            incomplete_obj.send_robust(sender=episode)
        else:
            cache.set(key, episode)
        return episode

    if create:
        episode = Episode()
        episode.created_timestamp = get_timestamp(datetime.utcnow())
        episode.podcast = podcast_id
        episode.urls = [episode_url]
        episode.save()
        incomplete_obj.send_robust(sender=episode)
        return episode

    return None
示例#12
0
文件: podcast.py 项目: fk-lx/mygpo
def podcast_for_slug(slug):

    if not slug:
        raise QueryParameterMissing('slug')

    db = get_main_database()
    obj = get_single_result(db, 'podcasts/by_slug',
            startkey     = [slug, None],
            endkey       = [slug, {}],
            include_docs = True,
            wrapper      = _wrap_podcast_group_key1,
        )

    if not obj:
        return None

    if obj.needs_update:
        incomplete_obj.send_robust(sender=obj)

    return obj
示例#13
0
文件: episode.py 项目: fk-lx/mygpo
def episodes_by_id(episode_ids):

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

    if not episode_ids:
        return []

    r = Episode.view('episodes/by_id',
            include_docs = True,
            keys         = episode_ids,
        )

    episodes = list(r)

    for episode in episodes:
        if episode.needs_update:
            incomplete_obj.send_robust(sender=episode)

    return episodes
示例#14
0
文件: episode.py 项目: fk-lx/mygpo
def episode_for_oldid(oldid):

    if not oldid:
        raise QueryParameterMissing('oldid')

    oldid = int(oldid)
    db = get_main_database()
    episode = get_single_result(db, 'episodes/by_oldid',
            key          = oldid,
            limit        = 1,
            include_docs = True,
            schema       = Episode,
        )

    if not episode:
        return None

    if episode.needs_update:
        incomplete_obj.send_robust(sender=episode)

    return episode
示例#15
0
文件: podcast.py 项目: fk-lx/mygpo
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
示例#16
0
文件: episode.py 项目: fk-lx/mygpo
def episode_for_slug(podcast_id, episode_slug):

    if not podcast_id:
        raise QueryParameterMissing('podcast_id')

    if not episode_slug:
        raise QueryParameterMissing('episode_slug')

    db = get_main_database()
    episode = get_single_result(db, 'episodes/by_slug',
            key          = [podcast_id, episode_slug],
            include_docs = True,
            schema       = Episode,
        )

    if not episode:
        return None

    if episode.needs_update:
        incomplete_obj.send_robust(sender=episode)

    return episode
示例#17
0
文件: episode.py 项目: fk-lx/mygpo
def episode_by_id(episode_id, current_id=False):

    if not episode_id:
        raise QueryParameterMissing('episode_id')

    db = get_main_database()

    episode = get_single_result(db, 'episodes/by_id',
            key          = episode_id,
            include_docs = True,
            schema       = Episode,
        )

    if not episode:
        return None

    if current_id and episode._id != episode_id:
        raise MergedIdException(episode, episode._id)

    if episode.needs_update:
        incomplete_obj.send_robust(sender=episode)

    return episode
示例#18
0
文件: podcast.py 项目: fk-lx/mygpo
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
示例#19
0
文件: podcast.py 项目: fk-lx/mygpo
def podcast_for_url(url, create=False):

    if not url:
        raise QueryParameterMissing('url')

    key = 'podcast-by-url-%s' % sha1(url.encode('utf-8')).hexdigest()

    podcast = cache.get(key)
    if podcast:
        return podcast

    db = get_main_database()
    podcast_group = get_single_result(db, 'podcasts/by_url',
            key          = url,
            include_docs = True,
            wrapper      = _wrap_pg,
        )

    if podcast_group:
        podcast = podcast_group.get_podcast_by_url(url)

        if podcast.needs_update:
            incomplete_obj.send_robust(sender=podcast)
        else:
            cache.set(key, podcast)

        return podcast

    if create:
        podcast = Podcast()
        podcast.created_timestamp = get_timestamp(datetime.utcnow())
        podcast.urls = [url]
        podcast.save()
        incomplete_obj.send_robust(sender=podcast)
        return podcast

    return None