From 77f1412c0cd5d4d98b49b8ebae14fbab905f9396 Mon Sep 17 00:00:00 2001 From: hillerliao Date: Tue, 10 Aug 2021 21:21:17 +0800 Subject: [PATCH] mp status from sogou --- rsshub/blueprints/main.py | 8 +++++++- rsshub/spiders/mp/gh.py | 32 ++++++++++++++++++++++++++++++++ rsshub/templates/main/atom.xml | 1 + 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 rsshub/spiders/mp/gh.py diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index 65f8a51..59487ba 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -169,7 +169,13 @@ def chouti_section(category=''): def chouti_search(category=''): from rsshub.spiders.chouti.search import ctx return render_template('main/atom.xml', **filter_content(ctx(category))) + @bp.route('/mp/tag//') def mp_tag(mp='', tag=''): from rsshub.spiders.mp.tag import ctx - return render_template('main/atom.xml', **filter_content(ctx(mp,tag))) \ No newline at end of file + return render_template('main/atom.xml', **filter_content(ctx(mp,tag))) + +@bp.route('/mp/gh/') +def mp_gh(gh=''): + from rsshub.spiders.mp.gh import ctx + return render_template('main/atom.xml', **filter_content(ctx(gh))) \ No newline at end of file diff --git a/rsshub/spiders/mp/gh.py b/rsshub/spiders/mp/gh.py new file mode 100644 index 0000000..04aecf7 --- /dev/null +++ b/rsshub/spiders/mp/gh.py @@ -0,0 +1,32 @@ +from rsshub.utils import fetch + +domain = 'https://weixin.sogou.com' + +def parse(post): + item = {} + + if dd_num > 1: + item['description'] = item['title'] = post.css('a::text').get() + item['link'] = domain + post.css('a::attr(href)').get() + item['pubDate'] = post.css('script::text').get().split('\'')[-2] + else: + item['description'] = item['title'] = '近期没有新文章' + item['link'] = url + return item + +def ctx(gh=''): + global url + url = f"{domain}/weixin?query={gh}" + tree = fetch(url) + global dd_num + dd_num = len( tree.css('dd') ) + posts = [ tree.css('dd')[-1] ] + mp_name = tree.css('p.tit a::text').get() + mp_description = tree.css('dd::text')[0].get() + return { + 'title': f'{mp_name}-公众号', + 'link': url, + 'description': mp_description, + 'author': 'hillerliao', + 'items': list(map(parse, posts)) + } \ No newline at end of file diff --git a/rsshub/templates/main/atom.xml b/rsshub/templates/main/atom.xml index 57eb99f..b3a62bf 100644 --- a/rsshub/templates/main/atom.xml +++ b/rsshub/templates/main/atom.xml @@ -5,6 +5,7 @@ zh-cn {{link}} <![CDATA[{{title|safe}}]]> +