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
def submit_a_feed(request): """ 用户添加一个自定义的订阅源 """ feed_url = request.POST.get('url', '').strip()[:1024] user = get_login_user(request) if feed_url: host = get_host_name(feed_url) if 'ershicimi.com' in host: rsp = parse_wemp_ershicimi(feed_url) elif host in settings.ALLOWED_HOSTS: rsp = parse_self_atom(feed_url) else: rsp = parse_atom(feed_url) if rsp: logger.warning(f"有新订阅源被提交:`{feed_url}") # 已登录用户,自动订阅 if user: add_user_sub_feeds(user.oauth_id, [ rsp['name'], ]) return JsonResponse(rsp) else: logger.warning(f"RSS 解析失败:`{feed_url}") return HttpResponseNotFound("Param error")
def update_all_wemp_feed(): """ 更新公众号源 """ logger.info('开始更新公众号内容') # 按照不同频率更新 feeds = Site.objects.filter(status='active', creator='wemp').order_by('-star') for site in feeds: try: parse_wemp_ershicimi(site.rss, update=True) except: logger.warning(f'爬取公众号出现异常:`{site.cname}') logger.info('更新公众号内容结束')
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
def submit_a_feed(request): """ 用户添加一个自定义的订阅源 """ feed_url = request.POST.get('url', '').strip()[:1024] user = get_login_user(request) if feed_url: host = get_host_name(feed_url) if 'ershicimi.com' in host: feed_url = feed_url.replace('/user/analysis?bid=', '/a/') rsp = parse_wemp_ershicimi(feed_url) elif host in settings.ALLOWED_HOSTS: rsp = parse_self_atom(feed_url) elif 'qnmlgb.tech' in host: rsp = parse_qnmlgb_atom(feed_url) else: rsp = parse_atom(feed_url) if rsp: logger.warning(f"有新订阅源被提交:`{feed_url}") # 已登录用户,自动订阅 if user: add_user_sub_feeds(user.oauth_id, [ rsp['site'], ]) # 异步更新任务 django_rq.enqueue(update_sites_async, [ rsp['site'], ]) return JsonResponse(rsp) else: logger.warning(f"RSS 解析失败:`{feed_url}") return HttpResponseNotFound("Param Error")