mirror of
https://github.com/d0zingcat/RSSHub-python.git
synced 2026-05-19 15:09:37 +00:00
add param support
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
from datetime import datetime
|
||||||
import click
|
import click
|
||||||
from flask import Flask, render_template
|
from flask import Flask, render_template
|
||||||
from flask.cli import with_appcontext
|
from flask.cli import with_appcontext
|
||||||
@@ -19,6 +20,7 @@ def create_app(config_name=None):
|
|||||||
register_blueprints(app)
|
register_blueprints(app)
|
||||||
register_extensions(app)
|
register_extensions(app)
|
||||||
register_errors(app)
|
register_errors(app)
|
||||||
|
register_context_processors(app)
|
||||||
register_cli(app)
|
register_cli(app)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
@@ -48,6 +50,13 @@ def register_errors(app):
|
|||||||
return render_template('errors/500.html'), 500
|
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):
|
def register_cli(app):
|
||||||
@app.cli.command()
|
@app.cli.command()
|
||||||
@with_appcontext
|
@with_appcontext
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from flask import Blueprint, render_template, current_app, request
|
from flask import Blueprint, render_template, request
|
||||||
|
|
||||||
|
|
||||||
bp = Blueprint('main', __name__)
|
bp = Blueprint('main', __name__)
|
||||||
|
|
||||||
@@ -9,12 +8,6 @@ def index():
|
|||||||
return render_template('main/index.html')
|
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()
|
@bp.app_template_global()
|
||||||
def filter_content(ctx):
|
def filter_content(ctx):
|
||||||
include_title = request.args.get('include_title')
|
include_title = request.args.get('include_title')
|
||||||
@@ -34,13 +27,8 @@ def filter_content(ctx):
|
|||||||
|
|
||||||
|
|
||||||
#---------- feed路由从这里开始 -----------#
|
#---------- feed路由从这里开始 -----------#
|
||||||
@bp.route('/guokr/scentific')
|
@bp.route('/chuansongme/articles/<string:category>')
|
||||||
def guokr_scientific():
|
@bp.route('/chuansongme/articles')
|
||||||
from rsshub.spiders.guokr.scientific import ctx
|
def chuansongme_articles(category=''):
|
||||||
return render_template('main/atom.xml', **filter_content(ctx))
|
from rsshub.spiders.chuansongme.articles import ctx
|
||||||
|
return render_template('main/atom.xml', **filter_content(ctx(category)))
|
||||||
|
|
||||||
@bp.route('/toutiao/today')
|
|
||||||
def toutiao_today():
|
|
||||||
from rsshub.spiders.toutiao.today import ctx
|
|
||||||
return render_template('main/atom.xml', **filter_content(ctx))
|
|
||||||
|
|||||||
22
rsshub/spiders/chuansongme/articles.py
Normal file
22
rsshub/spiders/chuansongme/articles.py
Normal file
@@ -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))
|
||||||
|
}
|
||||||
@@ -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']}<br><img referrerpolicy='no-referrer' src={d['image_info']['url']}"
|
|
||||||
item['pubDate'] = d['date_published']
|
|
||||||
item['link'] = d['url']
|
|
||||||
return item
|
|
||||||
|
|
||||||
|
|
||||||
ctx = {
|
|
||||||
'title': '果壳网 科学人',
|
|
||||||
'link': 'https://www.guokr.com/scientific',
|
|
||||||
'description': '果壳网 科学人',
|
|
||||||
'author': 'alphardex',
|
|
||||||
'items': list(map(parse, data))
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
from rsshub.utils import fetch
|
|
||||||
|
|
||||||
base_url = 'https://toutiao.io'
|
|
||||||
tree = fetch(base_url)
|
|
||||||
items = []
|
|
||||||
posts = tree.css('.posts .post')
|
|
||||||
|
|
||||||
for post in posts:
|
|
||||||
item = {}
|
|
||||||
item['title'] = post.css('.title a::attr(title)').extract_first()
|
|
||||||
item['description'] = ''
|
|
||||||
item['pubDate'] = ''
|
|
||||||
item['link'] = base_url + post.css('.title a::attr(href)').extract_first()
|
|
||||||
items.append(item)
|
|
||||||
|
|
||||||
ctx = {
|
|
||||||
'title': '开发者头条:今日头条',
|
|
||||||
'link': 'https://toutiao.io',
|
|
||||||
'description': '开发者头条:今日头条',
|
|
||||||
'author': 'alphardex',
|
|
||||||
'items': items
|
|
||||||
}
|
|
||||||
@@ -13,8 +13,8 @@
|
|||||||
<entry>
|
<entry>
|
||||||
<id>{{item.link}}</id>
|
<id>{{item.link}}</id>
|
||||||
<title><![CDATA[{{item.title|safe}}]]></title>
|
<title><![CDATA[{{item.title|safe}}]]></title>
|
||||||
<published>{{item.pubDate}}</published>
|
<published>{{item.pubDate|default(now)}}</published>
|
||||||
<updated>{{item.pubDate}}</updated>
|
<updated>{{item.pubDate|default(now)}}</updated>
|
||||||
<link href="{{item.link}}"/>
|
<link href="{{item.link}}"/>
|
||||||
<content type="html" src="{{item.link}}"><![CDATA[{{item.description|safe}}]]></content>
|
<content type="html" src="{{item.link}}"><![CDATA[{{item.description|safe}}]]></content>
|
||||||
</entry>
|
</entry>
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
{% extends "layout.html" %}
|
|
||||||
|
|
||||||
{% block title %}All Feeds{% endblock title %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="list-group">
|
|
||||||
{% for rule in rules %}
|
|
||||||
<a href="{{rule.rule}}" class="list-group-item list-group-item-action">{{rule.endpoint[5:]}}</a>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endblock content %}
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
<h1 class="display-4">Welcome to RSSHub!</h1>
|
<h1 class="display-4">Welcome to RSSHub!</h1>
|
||||||
<p class="lead">If you see this page, the RSSHub is successfully installed and working.</p>
|
<p class="lead">If you see this page, the RSSHub is successfully installed and working.</p>
|
||||||
<p>
|
<p>
|
||||||
<a class="btn btn-primary btn-lg" role="button" href="{{url_for('main.feeds')}}">View All Feeds</a>
|
<a class="btn btn-primary btn-lg" role="button" target="_blank" href="https://github.com/alphardex/RSSHub-python">View Source</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user