diff --git a/rsshub/__init__.py b/rsshub/__init__.py index 33e0dc9..56ebe03 100644 --- a/rsshub/__init__.py +++ b/rsshub/__init__.py @@ -1,4 +1,5 @@ import os +from datetime import datetime import click from flask import Flask, render_template from flask.cli import with_appcontext @@ -19,6 +20,7 @@ def create_app(config_name=None): register_blueprints(app) register_extensions(app) register_errors(app) + register_context_processors(app) register_cli(app) return app @@ -48,6 +50,13 @@ def register_errors(app): return render_template('errors/500.html'), 500 +def register_context_processors(app): + @app.context_processor + def inject_date_now(): + now = datetime.utcnow() + return {'now': now} + + def register_cli(app): @app.cli.command() @with_appcontext diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index de27650..b838153 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -1,5 +1,4 @@ -from flask import Blueprint, render_template, current_app, request - +from flask import Blueprint, render_template, request bp = Blueprint('main', __name__) @@ -9,12 +8,6 @@ def index(): return render_template('main/index.html') -@bp.route('/feeds') -def feeds(): - feed_rules = [rule for rule in current_app.url_map._rules if 'main' in rule.endpoint][:-2] - return render_template('main/feeds.html', rules=feed_rules) - - @bp.app_template_global() def filter_content(ctx): include_title = request.args.get('include_title') @@ -34,13 +27,8 @@ def filter_content(ctx): #---------- feed路由从这里开始 -----------# -@bp.route('/guokr/scentific') -def guokr_scientific(): - from rsshub.spiders.guokr.scientific import ctx - return render_template('main/atom.xml', **filter_content(ctx)) - - -@bp.route('/toutiao/today') -def toutiao_today(): - from rsshub.spiders.toutiao.today import ctx - return render_template('main/atom.xml', **filter_content(ctx)) +@bp.route('/chuansongme/articles/') +@bp.route('/chuansongme/articles') +def chuansongme_articles(category=''): + from rsshub.spiders.chuansongme.articles import ctx + return render_template('main/atom.xml', **filter_content(ctx(category))) diff --git a/rsshub/spiders/chuansongme/articles.py b/rsshub/spiders/chuansongme/articles.py new file mode 100644 index 0000000..f3e2468 --- /dev/null +++ b/rsshub/spiders/chuansongme/articles.py @@ -0,0 +1,22 @@ +from rsshub.utils import fetch + +domain = 'https://chuansongme.com' + + +def parse(post): + item = {} + item['title'] = post.css('a.question_link::text').extract()[-1].strip() + item['link'] = f"{domain}{post.css('a.question_link::attr(href)').extract_first()}" + return item + + +def ctx(category=''): + tree = fetch(f"{domain}/{category}") + posts = tree.css('.feed_body .pagedlist_item') + return { + 'title': '传送门', + 'link': 'https://chuansongme.com', + 'description': '传送门:微信公众号订阅', + 'author': 'alphardex', + 'items': list(map(parse, posts)) + } \ No newline at end of file diff --git a/rsshub/spiders/guokr/scientific.py b/rsshub/spiders/guokr/scientific.py deleted file mode 100644 index 4911352..0000000 --- a/rsshub/spiders/guokr/scientific.py +++ /dev/null @@ -1,23 +0,0 @@ -import requests - -data = requests.get( - 'https://www.guokr.com/apis/minisite/article.json?retrieve_type=by_subject' -).json()['result'] - - -def parse(d): - item = {} - item['title'] = d['title'] - item['description'] = f"{d['summary']}
{{item.link}} <![CDATA[{{item.title|safe}}]]> - {{item.pubDate}} - {{item.pubDate}} + {{item.pubDate|default(now)}} + {{item.pubDate|default(now)}} diff --git a/rsshub/templates/main/feeds.html b/rsshub/templates/main/feeds.html deleted file mode 100644 index 88e808a..0000000 --- a/rsshub/templates/main/feeds.html +++ /dev/null @@ -1,11 +0,0 @@ -{% extends "layout.html" %} - -{% block title %}All Feeds{% endblock title %} - -{% block content %} -
- {% for rule in rules %} - {{rule.endpoint[5:]}} - {% endfor %} -
-{% endblock content %} \ No newline at end of file diff --git a/rsshub/templates/main/index.html b/rsshub/templates/main/index.html index 95dca1d..ba61cdf 100644 --- a/rsshub/templates/main/index.html +++ b/rsshub/templates/main/index.html @@ -7,7 +7,7 @@

Welcome to RSSHub!

If you see this page, the RSSHub is successfully installed and working.

- View All Feeds + View Source

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