def test_translator_false_input(client): try: translator(app=None) except Exception as e: assert type(e) == AttributeError try: translator(app=app, cache=200) except Exception as e: assert type(e) == AttributeError remove(eng.file_name)
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 import Flask from flask_googletrans import translator from .index import index from .dixiana import dixiana from .efrain import efrain from .landia import landia from .arturo import arturo from .carlos import carlos from .about import about from .mdm import mdm app = Flask(__name__) app.config.from_pyfile('config/config.cfg') ts = translator(app=app, cache=True, fail_safe=False, service_urls=[ 'translate.googleapis.com', 'translate.google.com', 'translate.google.co.kr' ]) app.register_blueprint(index) app.register_blueprint(dixiana) app.register_blueprint(efrain) app.register_blueprint(landia) app.register_blueprint(arturo) app.register_blueprint(carlos) app.register_blueprint(about) app.register_blueprint(mdm)
import os from os import listdir from os.path import isfile, join import datetime import uuid import subprocess from flask_googletrans import translator from random import randint #from functions import * STATIC_DIR = os.path.abspath('./static') TEMPLATE_DIR = os.path.abspath('./views') app = Flask(__name__, template_folder=TEMPLATE_DIR, static_folder=STATIC_DIR) ts = translator(app) @app.route('/postXML', methods=['POST', 'GET']) def postXML(): cur_str = str(request.json) data = cur_str.split('xlow') print(data) xml = data[0] data2 = data[1].split("xhigh") xlow = data2[0] xhigh = data2[1] #xhigh = int(data[1].replace('xhigh', '').strip()) print(xml) print(xlow)
def __init__(self): app = Flask(__name__) self.translator = translator(app)
def toMimic(data): for d in dirs: if not path.isdir(d): mkdir(d) while True: tFile = str(randint(1, 9999999)) + '.html' if not path.isfile(tFile): break with open(path.join(dirs[0], tFile), 'w+') as file: file.write(data) return tFile app = Flask(__name__) eng = translator(app=app, route=True, cache=True) @app.route('/translate') def tran(): return render_template( toMimic( '{{ translate(text="%s", src="%s", dest=["%s"]) }}' % ( text, src, dest ) ) ) @fixture def client():
from flask_admin import Admin from flask_admin.contrib.sqla import ModelView from flask_admin.menu import MenuView, MenuLink from flask_whooshee import Whooshee from flask_googletrans import translator from flask_marshmallow import Marshmallow app = Flask(__name__) app.config.from_object(Config) db = SQLAlchemy(app) migrate = Migrate(app, db) login = LoginManager(app) bootstrap = Bootstrap(app) admin = Admin(app) whooshee = Whooshee(app) ts = translator(app, cache=True, route=True) ma = Marshmallow(app) whooshee.reindex() from wtforms import SelectField from app import routes, models from app.models import User, Student, Plan, Comment, Tests, Strategy admin.add_link(MenuLink(name='Return to RTI page', category='', url='/RTI')) class UserView(ModelView): column_list = ('name', 'employee_id', 'username', 'email', 'access_level', 'school', 'secondary', 'third', 'fourth') column_searchable_list = ('username', 'email') # this is to exclude the password field from list_view:
def create_app(config_class=Config): app = Flask(__name__) app.config.from_object(config_class) ts = translator(app) Mobility(app) db.init_app(app) migrate.init_app(app, db) login.init_app(app) mail.init_app(app) bootstrap.init_app(app) moment.init_app(app) babel.init_app(app) app.elasticsearch = Elasticsearch([app.config['ELASTICSEARCH_URL']]) \ if app.config['ELASTICSEARCH_URL'] else None app.redis = Redis.from_url(app.config['REDIS_URL']) app.task_queue = rq.Queue('streamfish-tasks', connection=app.redis) from app.errors import bp as errors_bp app.register_blueprint(errors_bp) from app.auth import bp as auth_bp app.register_blueprint(auth_bp, url_prefix='/auth') from app.main import bp as main_bp app.register_blueprint(main_bp) from app.api import bp as api_bp app.register_blueprint(api_bp, url_prefix='/api') if not app.debug and not app.testing: if app.config['MAIL_SERVER']: auth = None if app.config['MAIL_USERNAME'] or app.config['MAIL_PASSWORD']: auth = (app.config['MAIL_USERNAME'], app.config['MAIL_PASSWORD']) secure = None if app.config['MAIL_USE_TLS']: secure = () mail_handler = SMTPHandler( mailhost=(app.config['MAIL_SERVER'], app.config['MAIL_PORT']), fromaddr='no-reply@' + app.config['MAIL_SERVER'], toaddrs=app.config['ADMINS'], subject='StreamfishFailure', credentials=auth, secure=secure) mail_handler.setLevel(logging.ERROR) app.logger.addHandler(mail_handler) if app.config['LOG_TO_STDOUT']: stream_handler = logging.StreamHandler() stream_handler.setLevel(logging.INFO) app.logger.addHandler(stream_handler) else: if not os.path.exists('logs'): os.mkdir('logs') file_handler = RotatingFileHandler('logs/microblog.log', maxBytes=10240, backupCount=10) file_handler.setFormatter( logging.Formatter('%(asctime)s %(levelname)s: %(message)s ' '[in %(pathname)s:%(lineno)d]')) file_handler.setLevel(logging.INFO) app.logger.addHandler(file_handler) app.logger.setLevel(logging.INFO) app.logger.info('Welcome') if app.config['LOG_TO_STDOUT']: stream_handler = logging.StreamHandler() stream_handler.setLevel(logging.INFO) app.logger.addHandler(stream_handler) else: if not os.path.exists('logs'): os.mkdir('logs') file_handler = RotatingFileHandler('logs/microblog.log', maxBytes=10240, backupCount=10) file_handler.setFormatter( logging.Formatter('%(asctime)s %(levelname)s: %(message)s ' '[in %(pathname)s:%(lineno)d]')) file_handler.setLevel(logging.INFO) app.logger.addHandler(file_handler) app.logger.setLevel(logging.INFO) app.logger.info('Streamfishstartup') return app