mirror of
https://github.com/d0zingcat/RSSHub-python.git
synced 2026-05-14 15:09:23 +00:00
add cninfo announcement
This commit is contained in:
@@ -1,70 +1,70 @@
|
||||
import os
|
||||
from datetime import datetime
|
||||
import click
|
||||
from flask import Flask, render_template
|
||||
from flask.cli import with_appcontext
|
||||
from rsshub.config import config
|
||||
from rsshub.extensions import *
|
||||
from rsshub.blueprints.main import bp as main_bp
|
||||
from rsshub.utils import XMLResponse
|
||||
|
||||
|
||||
def create_app(config_name=None):
|
||||
if config_name is None:
|
||||
config_name = os.getenv('FLASK_CONFIG', 'development')
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(config[config_name])
|
||||
app.response_class = XMLResponse
|
||||
|
||||
register_blueprints(app)
|
||||
register_extensions(app)
|
||||
register_errors(app)
|
||||
register_context_processors(app)
|
||||
register_cli(app)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
def register_extensions(app):
|
||||
bootstrap.init_app(app)
|
||||
debugtoolbar.init_app(app)
|
||||
moment.init_app(app)
|
||||
|
||||
|
||||
def register_blueprints(app):
|
||||
app.register_blueprint(main_bp)
|
||||
|
||||
|
||||
def register_errors(app):
|
||||
@app.errorhandler(400)
|
||||
def bad_request(e):
|
||||
return render_template('errors/400.html'), 400
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(e):
|
||||
return render_template('errors/404.html'), 404
|
||||
|
||||
@app.errorhandler(500)
|
||||
def internal_server_error(e):
|
||||
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
|
||||
def ptshell():
|
||||
"""Use ptpython as shell."""
|
||||
try:
|
||||
from ptpython.repl import embed
|
||||
if not app.config['TESTING']:
|
||||
embed(app.make_shell_context())
|
||||
except ImportError:
|
||||
click.echo('ptpython not installed! Use the default shell instead.')
|
||||
import os
|
||||
from datetime import datetime
|
||||
import click
|
||||
from flask import Flask, render_template
|
||||
from flask.cli import with_appcontext
|
||||
from rsshub.config import config
|
||||
from rsshub.extensions import *
|
||||
from rsshub.blueprints.main import bp as main_bp
|
||||
from rsshub.utils import XMLResponse
|
||||
|
||||
|
||||
def create_app(config_name=None):
|
||||
if config_name is None:
|
||||
config_name = os.getenv('FLASK_CONFIG', 'development')
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(config[config_name])
|
||||
app.response_class = XMLResponse
|
||||
|
||||
register_blueprints(app)
|
||||
register_extensions(app)
|
||||
register_errors(app)
|
||||
register_context_processors(app)
|
||||
register_cli(app)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
def register_extensions(app):
|
||||
bootstrap.init_app(app)
|
||||
debugtoolbar.init_app(app)
|
||||
moment.init_app(app)
|
||||
|
||||
|
||||
def register_blueprints(app):
|
||||
app.register_blueprint(main_bp)
|
||||
|
||||
|
||||
def register_errors(app):
|
||||
@app.errorhandler(400)
|
||||
def bad_request(e):
|
||||
return render_template('errors/400.html'), 400
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(e):
|
||||
return render_template('errors/404.html'), 404
|
||||
|
||||
@app.errorhandler(500)
|
||||
def internal_server_error(e):
|
||||
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
|
||||
def ptshell():
|
||||
"""Use ptpython as shell."""
|
||||
try:
|
||||
from ptpython.repl import embed
|
||||
if not app.config['TESTING']:
|
||||
embed(app.make_shell_context())
|
||||
except ImportError:
|
||||
click.echo('ptpython not installed! Use the default shell instead.')
|
||||
|
||||
Reference in New Issue
Block a user