Beispiel #1
0
def tell(dst, content, expire_seconds):
    if content:
        content = json.loads(content)
    expire_at = None
    if expire_seconds:
        expire_at = int(time.time()) + expire_seconds
    scheduler.tell(dst, content=content, expire_at=expire_at)
Beispiel #2
0
def feed_create(
    request, url: _SCHEMA_FEED_CREATE_URL
) -> T.dict(
        is_ready=T.bool,
        feed=FeedSchema.optional,
        feed_creation=FeedCreationSchema.optional,
):
    """Deprecated, use feed_import instead."""
    try:
        feed, feed_creation = UnionFeed.create_by_url(url=url,
                                                      user_id=request.user.id)
    except FeedExistError:
        return Response({'message': 'already exists'}, status=400)
    if feed_creation:
        scheduler.tell(
            'worker_rss.find_feed',
            dict(
                feed_creation_id=feed_creation.id,
                url=feed_creation.url,
            ))
    return dict(
        is_ready=bool(feed),
        feed=feed.to_dict() if feed else None,
        feed_creation=feed_creation.to_dict() if feed_creation else None,
    )
Beispiel #3
0
def update_story_images(storys=None):
    story_ids = _get_story_ids(storys)
    LOG.info('total %s storys', len(story_ids))
    for story_id in tqdm.tqdm(story_ids, ncols=80, ascii=True):
        story = Story.objects.get(pk=story_id)
        scheduler.tell('harbor_rss.update_story_images', dict(
            story_id=story_id,
            story_url=story.link,
            images=[],
        ))
Beispiel #4
0
def feed_create(request, url: T.url.default_schema('http')) -> T.dict(
    is_ready=T.bool,
    feed=FeedSchema.optional,
    feed_creation=FeedCreationSchema.optional,
):
    try:
        feed, feed_creation = UnionFeed.create_by_url(url=url, user_id=request.user.id)
    except FeedExistError:
        return Response({'message': 'already exists'}, status=400)
    if feed_creation:
        scheduler.tell('worker_rss.find_feed', dict(
            feed_creation_id=feed_creation.id,
            url=feed_creation.url,
        ))
    return dict(
        is_ready=bool(feed),
        feed=feed.to_dict() if feed else None,
        feed_creation=feed_creation.to_dict() if feed_creation else None,
    )
Beispiel #5
0
def refresh_feed(feeds, union_feeds, key, expire=None):
    feed_ids = []
    if feeds:
        feed_ids.extend(_get_feed_ids(feeds))
    if union_feeds:
        feed_ids.extend(_decode_union_feed_ids(union_feeds))
    if key:
        cond = Q(url__contains=key) | Q(title__contains=key)
        feed_objs = Feed.objects.filter(cond).only('id').all()
        feed_ids.extend(x.id for x in feed_objs)
    feed_ids = list(sorted(set(feed_ids)))
    expire_at = time.time() + expire * 60 * 60
    for feed_id in tqdm.tqdm(feed_ids, ncols=80, ascii=True):
        feed = Feed.objects.only('id', 'url', 'use_proxy').get(pk=feed_id)
        scheduler.tell('worker_rss.sync_feed', dict(
            feed_id=feed.id,
            url=feed.url,
            use_proxy=feed.use_proxy,
            is_refresh=True,
        ), expire_at=expire_at)