def create_app(config={}): ''' Create the flask app and setup extensions and blueprints. Returns ------- app: Flask app app with settings and blueprints loadeds. ''' app = Flask(__name__, static_folder=absolute_path('static'), template_folder=absolute_path('templates')) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + absolute_path( 'data.sqlite') # Autoreload if templates change app.config['TEMPLATES_AUTO_RELOAD'] = True # flask_upload settings # app.config['MAX_CONTENT_LENGTH'] = 500 * 1024 * 1024 # Remove Upload limit. FIX ISSUE app.config['UPLOADED_FILES_DEST'] = absolute_path('static/multimedia') app.config['UPLOADED_FILES_ALLOW'] = reduce(lambda sum, group: sum + group, SUPPORTED_MEDIA_FILES) app.config['SECRET_KEY'] = os.urandom(24) app.config.update(config) # Initiating extensions before registering blueprints PageDown(app) Moment(app) QRcode(app) configure_uploads(app, files) login_manager.init_app(app) db.init_app(app) datepicker( app, local=['static/css/jquery-ui.min.css', 'static/jquery-ui.min.js']) colorpicker(app, local=['static/css/spectrum.css', 'static/spectrum.js']) fontpicker(app, local=[ 'static/jquery-ui.min.js', 'static/css/jquery-ui.min.css', 'static/webfont.js', 'static/webfont.select.js', 'static/css/webfont.select.css' ]) lessc(app) minify(app, js=True, caching_limit=3, fail_safe=True, bypass=['/touch/<int:a>', '/serial/<int:t_id>', '/display']) gtts(app=app, route=True) gtranslator.init_app(app) # Register blueprints app.register_blueprint(administrate) app.register_blueprint(core) app.register_blueprint(cust_app) app.register_blueprint(manage_app) app.jinja_env.add_extension('jinja2.ext.loopcontrols') return app
def test_false_app_gtts(client): ''' test gtts false app input. ''' try: gtts(app=None) except Exception as e1: assert type(e1) == AttributeError try: gtts(app=app, temporary=200) except Exception as e2: assert type(e2) == TypeError assert gtts(app=app, tempdir='/').tempdir.endswith('flask_gtts') is True
def create_app(): app = Flask(__name__, static_folder=r_path('static'), template_folder=r_path('templates')) if getattr(sys, 'frozen', False): basedir = os.path.dirname(sys.executable) else: basedir = os.path.abspath(os.path.dirname(__file__)) # bootstrap = Bootstrap(app) pagedown = PageDown(app) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + r_path( 'data.sqlite') # Autoreload if templates change app.config['TEMPLATES_AUTO_RELOAD'] = True # flask_upload settings # app.config['MAX_CONTENT_LENGTH'] = 500 * 1024 * 1024 # Remove Upload limit. FIX ISSUE app.config['UPLOADED_FILES_DEST'] = r_path('static/multimedia') app.config['UPLOADED_FILES_ALLOW'] = mdal app.config['SECRET_KEY'] = os.urandom(24) # Intiating extensions before registering blueprints moment = Moment(app) qrc = QRcode(app) configure_uploads(app, files) login_manager.init_app(app) db.init_app(app) datepicker( app, local=['static/css/jquery-ui.min.css', 'static/jquery-ui.min.js']) colorpicker(app, local=['static/css/spectrum.css', 'static/spectrum.js']) fontpicker(app, local=[ 'static/jquery-ui.min.js', 'static/css/jquery-ui.min.css', 'static/webfont.js', 'static/webfont.select.js', 'static/css/webfont.select.css' ]) lessc(app) minify(app, js=True, cache=True, fail_safe=True, bypass=['/touch/<int:a>', '/serial/<int:t_id>', '/display']) gtts(app=app, route=True) gtranslator.init_app(app) # Register blueprints app.register_blueprint(administrate) app.register_blueprint(core) app.register_blueprint(cust_app) app.register_blueprint(errorsh_app) app.register_blueprint(manage_app) app.jinja_env.add_extension('jinja2.ext.loopcontrols') return app
from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from flask_login import LoginManager from flask_uploads import UploadSet, ALL from flask_googletrans import translator from flask_gtts import gtts from app.constants import MIGRATION_FOLDER # NOTE: Work around for flask imports and registering blueprints # currently needed for sql alchemy, login manager and flask-uploads db = SQLAlchemy() migrate = Migrate(directory=MIGRATION_FOLDER, compare_type=True) login_manager = LoginManager() login_manager.login_view = "login" files = UploadSet('files', ALL) gtranslator = translator(cache=True, skip_app=True, fail_safe=True) gTTs = gtts(route=True, failsafe=True, logging=False)
from flask_sqlalchemy import SQLAlchemy from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user from flask_gtts import gtts #wtf forms from wtforms import StringField, PasswordField, BooleanField from wtforms.validators import InputRequired, Email, Length #chatterbot from chatterbot import ChatBot from chatterbot.trainers import ChatterBotCorpusTrainer, ListTrainer from chatterbot.conversation import Statement #werkuzeug from werkzeug.security import generate_password_hash, check_password_hash import re app = Flask(__name__) app.config['SECRET_KEY'] = 'thissecret' gtts(app) db_path = os.path.join(os.path.dirname(__file__), 'app.db') db_uri = 'sqlite:///{}'.format(db_path) app.config['SQLALCHEMY_DATABASE_URI'] = db_uri Bootstrap(app) db = SQLAlchemy(app) login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = 'login' class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(15), unique=True) email = db.Column(db.String(50), unique=True)
from flask import Flask, render_template from flask_gtts import gtts import GmailConnector app = Flask(__name__) gtts(app=app,temporary=True, # to remove audio files on exit tempdir='static/', # relative path in-which audio files will be stored route=False) # opens route on /gtts that takes /language/text as args to return gtts mp3 link) # inboxs=[ # { # 'from':'*****@*****.**', # 'subject':'testing', # 'content':'hi, how are you doing' # }, # { # 'from':'*****@*****.**', # 'subject':'testing', # 'content':'hi, how are you doing,glad to see you in this summer i hope we can met in indonesia right ?' # } # ] inboxs=GmailConnector.read_email() @app.route("/") def hello(): return render_template('index.html',inboxs = inboxs)
message = 'You are not allowed!' def prevent_header(function): @wraps(function) def wrapper(*args, **kwargs): if request.headers.get('prevent'): return message return function(*args, **kwargs) return wrapper eng = gtts(app, route=True, route_decorator=prevent_header, failsafe=True) text = 'something to say' language = 'en-uk' @app.route('/say') def say(): return render_template(mock_template( "{{sayit(lang='%s', text='%s')}}" % (language, text))) @app.route('/read') def read(): return render_template(mock_template("{{read()}}"))
# -*- coding: utf-8 -*- ''' This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ''' from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from flask_login import LoginManager from flask_uploads import UploadSet, ALL from flask_googletrans import translator from flask_gtts import gtts from app.constants import MIGRATION_FOLDER # NOTE: Work around for flask imports and registering blueprints # currently needed for sql alchemy, login manager and flask-uploads db = SQLAlchemy() migrate = Migrate(directory=MIGRATION_FOLDER) login_manager = LoginManager() login_manager.login_view = "login" files = UploadSet('files', ALL) gtranslator = translator(cache=True, skip_app=True, fail_safe=True) gTTs = gtts(route=True)
from flask_apscheduler import APScheduler from playsound import playsound from flask_gtts import gtts #initliazing our flask app, SQLAlchemy and Marshmallow app = Flask(__name__) auth = HTTPBasicAuth() # Authentication app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///cardsdatabase.db' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) ma = Marshmallow(app) scheduler = APScheduler() gtts(app, route=True, route_path='/gtts') class Card(db.Model): id = db.Column(db.Integer, primary_key=True) category = db.Column(db.String(100)) topic = db.Column(db.String(100)) question = db.Column(db.String(100000)) difficulty = db.Column(db.Integer) timestamp = db.Column(db.String(100), nullable=False, default=datetime.utcnow) #user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __init__(self, category, topic, question, difficulty, timestamp):