add param support

This commit is contained in:
alphardex
2019-01-17 10:00:10 +08:00
parent 8a2f334c80
commit 91d5ecf57a
8 changed files with 40 additions and 77 deletions

View File

@@ -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

View File

@@ -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/<string:category>')
@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)))

View 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))
}

View File

@@ -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))
}

View File

@@ -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
}

View File

@@ -13,8 +13,8 @@
<entry>
<id>{{item.link}}</id>
<title><![CDATA[{{item.title|safe}}]]></title>
<published>{{item.pubDate}}</published>
<updated>{{item.pubDate}}</updated>
<published>{{item.pubDate|default(now)}}</published>
<updated>{{item.pubDate|default(now)}}</updated>
<link href="{{item.link}}"/>
<content type="html" src="{{item.link}}"><![CDATA[{{item.description|safe}}]]></content>
</entry>

View File

@@ -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 %}

View File

@@ -7,7 +7,7 @@
<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>
<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>
</div>
{% endblock %}