diff --git a/Pipfile b/Pipfile index aacd0f6..bba1c60 100644 --- a/Pipfile +++ b/Pipfile @@ -5,6 +5,7 @@ name = "pypi" [packages] bootstrap-flask = "*" +feedparser = "*" flask-debugtoolbar = "*" flask-moment = "*" Flask = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 3a46458..9cbded3 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "2bf1ccf68553a24a83089a5c5f7e67c109abb959f66568559f8a1593fd878fd5" + "sha256": "244fdb2ca7e1595ca468c0f56bb8936b1fa6efce78ace99461e8ca813fe7114f" }, "pipfile-spec": 6, "requires": {}, @@ -81,6 +81,14 @@ ], "version": "==0.8.3" }, + "feedparser": { + "hashes": [ + "sha256:1b7f57841d9cf85074deb316ed2c795091a238adb79846bc46dccdaf80f9c59a", + "sha256:5ce0410a05ab248c8c7cfca3a0ea2203968ee9ff4486067379af4827a59f9661" + ], + "index": "pypi", + "version": "==6.0.8" + }, "flask": { "hashes": [ "sha256:315ded2ddf8a6281567edb27393010fe3406188bafbfe65a3339d5787d89e477", @@ -225,6 +233,12 @@ "markers": "python_version >= '3.7'", "version": "==62.2.0" }, + "sgmllib3k": { + "hashes": [ + "sha256:7868fb1c8bfa764c1ac563d3cf369c381d1325d36124933a726f29fcdaa812e9" + ], + "version": "==1.0.0" + }, "six": { "hashes": [ "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926", @@ -291,11 +305,11 @@ }, "coverage": { "hashes": [ - "sha256:03e2a7826086b91ef345ff18742ee9fc47a6839ccd517061ef8fa1976e652ce9", - "sha256:b78e5afb39941572209f71866aa0b206c12f0109835aa0d601e41552f9b3e620" + "sha256:2781c43bffbbec2b8867376d4d61916f5e9c4cc168232528562a61d1b4b01879", + "sha256:cc692c9ee18f0dd3214843779ba6b275ee4bb9b9a5745ba64265bce911aefd1a" ], "index": "pypi", - "version": "==6.3.2" + "version": "==6.3.3" }, "dill": { "hashes": [ @@ -422,11 +436,11 @@ }, "pylint": { "hashes": [ - "sha256:ced8968c3b699df0615e2a709554dec3ddac2f5cd06efadb69554a69eeca364a", - "sha256:f87e863a0b08f64b5230e7e779bcb75276346995737b2c0dc2793070487b1ff6" + "sha256:095567c96e19e6f57b5b907e67d265ff535e588fe26b12b5ebe1fc5645b2c731", + "sha256:705c620d388035bdd9ff8b44c5bcdd235bfb49d276d488dd2c8ff1736aa42526" ], "index": "pypi", - "version": "==2.13.8" + "version": "==2.13.9" }, "setuptools": { "hashes": [ diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index 630dbed..2424080 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -220,6 +220,12 @@ def bjnews_channel(category=''): from rsshub.spiders.bjnews.channel import ctx return render_template('main/atom.xml', **filter_content(ctx(category))) +@bp.route('/filter/') +def rss_filter(): + from rsshub.spiders.rssfilter.filter import ctx + feed_url = request.args.get("feed") + return render_template('main/atom.xml', **filter_content(ctx(feed_url))) + ''' @bp.route('/test') @bp.route('/test/测试') diff --git a/rsshub/spiders/rssfilter/filter.py b/rsshub/spiders/rssfilter/filter.py new file mode 100644 index 0000000..fa70b00 --- /dev/null +++ b/rsshub/spiders/rssfilter/filter.py @@ -0,0 +1,34 @@ +import requests +import feedparser + +from rsshub.utils import DEFAULT_HEADERS +from rsshub.utils import fetch + +def parse(post): + item = {} + item['title'] = post.title + item['description'] = post.summary + item['pubDate'] = post.published + item['link'] = post.link + return item + +def ctx(feed_url=''): + # tree = fetch(feed_url,headers=DEFAULT_HEADERS) + # title = tree.css('channel').css('title::text').get() + # description = tree.css('channel').css('description').get() + # posts = tree.css('item') + + feed = feedparser.parse(feed_url) + + title = feed.feed.title + description = feed.feed.subtitle + + posts = feed.entries + + return { + 'title': title, + 'link': feed_url, + 'description': description, + 'author': feed.feed.author, + 'items': list(map(parse, posts)) + } \ No newline at end of file diff --git a/rsshub/templates/main/feeds.html b/rsshub/templates/main/feeds.html index e51f920..b460af5 100644 --- a/rsshub/templates/main/feeds.html +++ b/rsshub/templates/main/feeds.html @@ -1,9 +1,40 @@ {% extends "layout.html" %} {% block title %}All Feeds{% endblock title %} {% block content %} + + +
举例:https://pyrsshub.vercel.app/filter?feed=https://sspai.com/feed&include_title=派早报
+参数:include_title 匹配标题
参数:include_description 匹配摘要
参数:exclude_title 排除标题
参数:exclude_description 排除摘要
参数:limit 限制条数
举例:https://pyrsshub.vercel.app/filter?feed=https://sspai.com/feed
+路由:/filter?feed=:feed
参数:feed [rss 地址]
+举例:https://rsshub.deta.dev/chuansongme/articles
+举例:https://pyrsshub.vercel.app/chuansongme/articles
路由:/chuansongme/articles/:category
参数:category [默认为“最新”]