From bdeb80cc123e761cde2eedd6c0151a173c526b80 Mon Sep 17 00:00:00 2001 From: hillerliao Date: Fri, 21 Feb 2020 21:34:03 +0800 Subject: [PATCH] add jiemian newsflash --- rsshub/blueprints/main.py | 4 ++++ rsshub/spiders/jiemian/newsflash.py | 34 +++++++++++++++++++++++++++++ rsshub/templates/main/feeds.html | 13 +++++++++++ 3 files changed, 51 insertions(+) create mode 100644 rsshub/spiders/jiemian/newsflash.py diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index aea8ace..83d4908 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -81,3 +81,7 @@ def earningsdate_businesswire(): from rsshub.spiders.earningsdate.businesswire import ctx return render_template('main/atom.xml', **filter_content(ctx())) +@bp.route('/jiemian/newsflash/') +def jiemian_newsflash(category=''): + from rsshub.spiders.jiemian.newsflash import ctx + return render_template('main/atom.xml', **filter_content(ctx(category))) \ No newline at end of file diff --git a/rsshub/spiders/jiemian/newsflash.py b/rsshub/spiders/jiemian/newsflash.py new file mode 100644 index 0000000..54f7a20 --- /dev/null +++ b/rsshub/spiders/jiemian/newsflash.py @@ -0,0 +1,34 @@ +import requests +import json +from parsel import Selector +from datetime import datetime, date + +domain = 'https://jiemian.com' + +def parse(post): + item = {} + item['title'] = post.css('a::text').extract_first() + item['description'] = post.css('p::text').extract()[-1].strip('】\n\t\t\t\t\t') + item['link'] = post.css('a::attr(href)').extract_first() + pubdate = post.xpath('//div[@class="item-news "]/preceding::div[@class="col-date"][last()-1]').css('div::text').extract_first() + cur_t =datetime.now().time().strftime("%H%M") + pub_t = post.css('.item-date').css('div::text').extract_first() + if pub_t.replace(':', '') < cur_t: + pubdate = date.today().isoformat() + item['pubDate'] = pubdate + ' ' + pub_t + return item + +def ctx(category=''): + res = requests.get(f"https://a.jiemian.com/index.php?m=lists&a=ajaxNews&page=1&cid={category}") + res = res.text[1:-1] + res = json.loads(res)['rst'] + tree = Selector(text=res) + posts = tree.css('.item-news') + items = list(map(parse, posts)) + return { + 'title': f'{category} 快讯 - 界面新闻', + 'link': f'{domain}//lists/{category}.html', + 'description': f'{category} 快讯 - 界面新闻', + 'author': 'hillerliao', + 'items': items + } \ No newline at end of file diff --git a/rsshub/templates/main/feeds.html b/rsshub/templates/main/feeds.html index cb2e622..14cc221 100644 --- a/rsshub/templates/main/feeds.html +++ b/rsshub/templates/main/feeds.html @@ -98,4 +98,17 @@
+ + +
+
+

界面快讯

+
界面快讯 by hillerliao
+

举例:https://rsshub-python.herokuapp.com/jiemian/newsflash/166

+

路由:/jiemian/newsflash/:category

+

参数:category [必填,见界面快讯栏目https://www.jiemian.com/lists/4.html]

+
+
+
+ {% endblock content %} \ No newline at end of file