Пример #1
0
def update_all_atom_cron():
    """
    定时更新所有普通源
    """
    now, sites = datetime.now(), []

    # 按照不同频率更新,区分用户自定义的和推荐的
    if now.hour % 2 == 0:
        sites = Site.objects.filter(status='active',
                                    creator='user').order_by('-star')
    elif now.hour % 2 == 1:
        sites = Site.objects.filter(status='active',
                                    creator='user',
                                    star__gte=9).order_by('-star')

    for site in sites:
        # 无人订阅的源且不推荐的源不更新
        if not is_active_rss(site.pk) and site.star < 9:
            continue

        # 是否已经更新过
        if not is_updated_site(site.pk):
            atom_spider(site)

    return True
Пример #2
0
def update_sites_async(sites, force_update=False):
    """
    异步更新某一批订阅源,只支持普通源和公众号的更新
    """
    for site_id in sites:
        try:
            site = Site.objects.get(status='active', pk=site_id)
        except:
            continue

        # 最近已经更新过了,跳过
        if not force_update and is_updated_site(site_id):
            continue

        if site.creator != 'system':
            logger.info(f"开始异步更新:{site_id}")

            host = get_host_name(site.rss)

            if 'ershicimi.com' in host:
                parse_wemp_ershicimi(site.rss, update=True)
            else:
                atom_spider(site)

    return True
Пример #3
0
def update_sites_async(sites, force_update=False):
    """
    异步更新某一批订阅源,只支持普通源
    """
    for site_id in sites:
        try:
            site = Site.objects.get(status='active',
                                    pk=site_id,
                                    creator='user')
        except:
            continue

        # 最近已经更新过了,跳过
        if not force_update and is_updated_site(site_id):
            continue

        logger.info(f"开始异步更新:{site_id}")
        atom_spider(site)

    return True
Пример #4
0
def update_all_wemp_cron():
    """
    更新微信公众号,每天 1~2 次
    """
    sites = Site.objects.filter(status='active',
                                creator='wemp').order_by('-star')

    for site in sites:
        # 无人订阅的源且不推荐的源不更新
        if not is_active_rss(site.pk) and site.star < 9:
            continue

        if not is_updated_site(site.pk):
            host = get_host_name(site.rss)

            if 'ershicimi.com' in host:
                parse_wemp_ershicimi(site.rss, update=True)
            elif 'qnmlgb.tech' in host:
                atom_spider(site)
            else:
                pass

    return True