Example #1
0
def do_save_feed_creation_result(
        ctx: ActorContext,
        feed_creation_id: T.int,
        messages: T.list(T.str),
        feed: FeedSchema.optional,
):
    with transaction.atomic():
        feed_dict = feed
        try:
            feed_creation = FeedCreation.get_by_pk(feed_creation_id)
        except FeedCreation.DoesNotExist:
            LOG.warning(f'feed creation {feed_creation_id} not exists')
            return
        if feed_creation.status == FeedStatus.READY:
            LOG.info(f'feed creation {feed_creation_id} is ready')
            return
        feed_creation.message = '\n\n'.join(messages)
        feed_creation.dt_updated = timezone.now()
        if not feed_dict:
            feed_creation.status = FeedStatus.ERROR
            feed_creation.save()
            FeedUrlMap(source=feed_creation.url,
                       target=FeedUrlMap.NOT_FOUND).save()
            return
        url = feed_dict['url']
        feed = Feed.get_first_by_url(url)
        if not feed:
            now = timezone.now()
            feed = Feed(url=url,
                        status=FeedStatus.READY,
                        reverse_url=reverse_url(url),
                        dt_updated=now,
                        dt_checked=now,
                        dt_synced=now)
            feed.save()
        feed_creation.status = FeedStatus.READY
        feed_creation.feed_id = feed.id
        feed_creation.save()
        user_feed = UserFeed.objects.filter(user_id=feed_creation.user_id,
                                            feed_id=feed.id).first()
        if user_feed:
            LOG.info('UserFeed#{} user_id={} feed_id={} already exists'.format(
                user_feed.id, feed_creation.user_id, feed.id))
        else:
            user_feed = UserFeed(
                user_id=feed_creation.user_id,
                feed_id=feed.id,
                is_from_bookmark=feed_creation.is_from_bookmark,
            )
            user_feed.save()
        FeedUrlMap(source=feed_creation.url, target=feed.url).save()
        if feed.url != feed_creation.url:
            FeedUrlMap(source=feed.url, target=feed.url).save()
    ctx.hope('harbor_rss.update_feed',
             dict(
                 feed_id=feed.id,
                 feed=validate_feed_output(feed_dict),
             ))
Example #2
0
File: rss.py Project: XZYCR7/rssant
def subscribe_changelog():
    changelog_url = CONFIG.root_url.rstrip('/') + '/changelog.atom'
    feed = Feed.objects.get(url=changelog_url)
    if not feed:
        click.echo(f'not found changelog feed url={changelog_url}')
        return
    click.echo(f'changelog feed {feed}')
    users = list(User.objects.all())
    click.echo(f'total {len(users)} users')
    for user in tqdm.tqdm(users, ncols=80, ascii=True):
        with transaction.atomic():
            user_feed = UserFeed.objects\
                .filter(user_id=user.id, feed_id=feed.id).first()
            if not user_feed:
                user_feed = UserFeed(
                    user_id=user.id,
                    feed_id=feed.id,
                    is_from_bookmark=False,
                )
                user_feed.save()
Example #3
0
 def _import_feeds(self, imports: list):
     result = UnionFeed.create_by_imports(user_id=self._tester.id,
                                          imports=imports)
     for creation in result.feed_creations:
         creation: FeedCreation
         feed = Feed(
             title=creation.title,
             url=creation.url,
             status=FeedStatus.READY,
             dt_updated=timezone.now(),
         )
         feed.save()
         user_feed = UserFeed(
             user=self._tester,
             feed=feed,
             title=creation.title,
             group=creation.group,
             dt_updated=timezone.now(),
         )
         user_feed.save()
         FeedUrlMap(source=creation.url, target=feed.url).save()
         FeedUrlMap(source=creation.url + '.c', target=feed.url).save()
     return result