Beispiel #1
0
def _create_feeds_by_imports(
    user,
    imports: list,
    group: str = None,
    is_from_bookmark=False,
):
    import_items = []
    for raw_item in imports:
        item_group = group
        if not item_group:
            item_group = raw_item.get('group')
        item_group = group_id_of(item_group)
        title = raw_item.get('title')
        item = FeedImportItem(url=raw_item['url'],
                              title=title,
                              group=item_group)
        import_items.append(item)
    result = UnionFeed.create_by_imports(imports=import_items, user_id=user.id)
    find_feed_tasks = []
    for feed_creation in result.feed_creations:
        find_feed_tasks.append(
            dict(dst='worker_rss.find_feed',
                 content=dict(
                     feed_creation_id=feed_creation.id,
                     url=feed_creation.url,
                 )))
    scheduler.batch_tell(find_feed_tasks)
    created_feeds = [x.to_dict() for x in result.created_feeds]
    feed_creations = [x.to_dict() for x in result.feed_creations]
    first_existed_feed = None
    if result.existed_feeds:
        first_existed_feed = result.existed_feeds[0].to_dict()
    return dict(
        total=result.total,
        num_created_feeds=len(result.created_feeds),
        num_existed_feeds=len(result.existed_feeds),
        num_feed_creations=len(result.feed_creations),
        first_existed_feed=first_existed_feed,
        created_feeds=created_feeds,
        feed_creations=feed_creations,
    )
Beispiel #2
0
def _create_feeds_by_urls(user, urls, is_from_bookmark=False):
    result = UnionFeed.create_by_url_s(urls=urls, user_id=user.id)
    find_feed_tasks = []
    for feed_creation in result.feed_creations:
        find_feed_tasks.append(
            dict(dst='worker_rss.find_feed',
                 content=dict(
                     feed_creation_id=feed_creation.id,
                     url=feed_creation.url,
                 )))
    scheduler.batch_tell(find_feed_tasks)
    created_feeds = [x.to_dict() for x in result.created_feeds]
    feed_creations = [x.to_dict() for x in result.feed_creations]
    return dict(
        total=result.total,
        num_created_feeds=len(result.created_feeds),
        num_existed_feeds=len(result.existed_feeds),
        num_feed_creations=len(result.feed_creations),
        created_feeds=created_feeds,
        feed_creations=feed_creations,
    )