示例#1
0
    def setUp(self):
        create_app("test")
        from application import app, db
        self.app = app

        with app.test_request_context():
            db.create_all()
            # Initialize database, if needed
            self.db_session = db.create_scoped_session()
示例#2
0
def grab():
    """获取最新feed数据"""
    new_posts_count = 0
    flask_app = create_app()

    with flask_app.app_context():
        # 通过feed抓取blog
        for blog in Blog.query:
            if blog.feed and blog.is_approved:
                try:
                    new_posts_count += grab_by_feed(blog)
                except Exception, e:
                    log = GrabLog(message=e, details=traceback.format_exc(), blog_id=blog.id)
                    db.session.add(log)
                    db.session.commit()

        # 通过spider抓取blog
        for spider in spiders:
            try:
                new_posts_count += grab_by_spider(spider)
            except Exception, e:
                blog = Blog.query.filter(Blog.url == spider.url).first_or_404()
                log = GrabLog(message=e, details=traceback.format_exc(), blog_id=blog.id)
                db.session.add(log)
                db.session.commit()
示例#3
0
    def __init__(self,url):
        """Inits webdriver and data."""
        self.url = url

        app = create_app()
        self.app = app
        with app.app_context():
            list = WpDataoptimumPlayContent.query.outerjoin(WpDataoptimumPlay,WpDataoptimumPlayContent.play_id==WpDataoptimumPlay.id).filter((
WpDataoptimumPlayContent.play_id==39)).with_entities(WpDataoptimumPlayContent.id,'post_url','title','username','from_user','to_user','self_symbol','object_symbol','content','play_id','carry_time',WpDataoptimumPlayContent.status).all()

        data = {}
        parent = {}
        for val in list:
            d = {"id":val.id,"post_url":val.post_url,"title":val.title,"username":val.username,"from_user":val.from_user,"to_user":val.to_user,"self_symbol":val.self_symbol,"object_symbol":val.object_symbol,"content":val.content,"play_id":val.play_id,"carry_time":val.carry_time,"status":val.status}
            data[val.id] = d

        for val in data:
            pid = data[val]['self_symbol'] + str(data[val]['play_id'])
            data[val]['pid'] = pid
            parent[pid] = data[val]

        pid = ''
        self.data_c = copy.deepcopy(data)
        # get parent data
        for val in list:
            if val.object_symbol:
                pid = val.object_symbol + str(val.play_id)
                if pid in parent.keys():
                    self.data_c[val.id]['parent'] = parent[pid]
示例#4
0
    def setUp(self):
        self.tb = testbed.Testbed()
        self.tb.activate()
        self.tb.init_memcache_stub()
        self.tb.init_urlfetch_stub()

        self.app = create_app()
        self.client = self.app.test_client(use_cookies=True)
示例#5
0
    def setup(self):
        # os.environ['MODE'] = 'TESTING'

        app = create_app()
        # self.app = app
        # self.client = app.test_client()
        with app.app_context():
            # me = WpDataoptimumRecord.query.filter((WpDataoptimumRecord.state==1)).first()
            val = WpDataoptimumPlayContent.query.join(WpDataoptimumPlay,WpDataoptimumPlayContent.play_id==WpDataoptimumPlay.id).filter(WpDataoptimumPlayContent.status==0)
            print val.title,val.post_url
示例#6
0
    def setup(self):
        os.environ['MODE'] = 'TESTING'

        app = create_app()
        self.app = app
        self.client = app.test_client()

        with app.app_context():
            db.drop_all()
            db.create_all()
    def setUp(self):
        self.tb = testbed.Testbed()
        self.tb.activate()
        self.tb.init_memcache_stub()

        self.app = create_app()
        self.app.debug = True
        self.test_app = self.app.test_client()
        create_routes(self.app)
        self.app.config['TESTING'] = True
        self.client = self.app.test_client(use_cookies=True)
示例#8
0
def main():
    if '--with-redis' in sys.argv:
        redis_requested = True
        sys.argv.remove('--with-redis')
    else:
        redis_requested = False

    app = create_app(os.environ['OSMPOINT_WORKDIR'])
    manager = Manager(app, default_server_actions=True)
    manager.add_action('migrate_to_redis', migrate_to_redis_cmd)

    with maybe_redis_server(app, redis_requested):
        manager.run()
示例#9
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     self.client = self.app.test_client(use_cookies=True)
     db.create_all()
     # create test user
     user = User(
         email='*****@*****.**',
         first_name='Alan',
         last_name='Smith',
         password='******'
         )
     db.session.add(user)
     db.session.commit()
示例#10
0
文件: __init__.py 项目: airdna/airdna
def make_celery(app = None):
    #from .utils import tasks
    from application import create_app
    app = app or create_app()
    celery = Celery(app.import_name, broker= app.config['CELERY_BROKER_URL'])
    celery.conf.update(app.config)
    TaskBase = celery.Task
    class ContextTask(TaskBase):
        abstract = True
        def __call__(self, *args, **kwargs):
            with app.app_context():
                return TaskBase.__call__(self, *args, **kwargs)
    celery.Task = ContextTask
    #tasks.celery = celery
    return celery
示例#11
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--reset_db", action='store_true', help="Delete all code in database")

    import controllers
    import models

    args = parser.parse_args()

    app = create_app()
    if args.reset_db:
        db.drop_all()
    db.create_all()

    populate()
    app.run(host=app.config['HOST'], port=app.config['PORT'])
    def setUp(self):
        super(FlaskTestCase, self).setUp()
        self.app = application.create_app("app", "config.TestingConfig")
        self.app_context = self.app.app_context()
        self.app_context.push()

        # !important must init_app after current_app is existed
        from application import init_app
        self.app = init_app(self.app)
        # !important must init_app after current_app is existed

        self.client = self.app.test_client(use_cookies=True)
        self._attach_logger_format(level = logging.DEBUG)

        # DO NOT move "import factories" from here
        import factories
        # DO NOT move "import factories" from here
        self._db = factories.init_db(self.app)
        self._create_fixtures()
示例#13
0
文件: manage.py 项目: suqi/mdpress
def worker(config):
    from application.extensions import celery
    app = create_app(config)
    app.app_context().push()
示例#14
0
文件: manage.py 项目: suqi/mdpress
def run_fcgi(config):
    from flup.server.fcgi import WSGIServer
    app = create_app(config)
    server = WSGIServer(app, bindAddress='/tmp/mdpress.sock')
    server.run()
from flask.ext.script import Manager

from application import create_app
from application import init_app

app = create_app("app", "config.DevelopmentConfig")
app = init_app(app)
manager = Manager(app)

@manager.command
def init_db():
    from models import db
    db.init_app(app)
    db.create_all()

if __name__ == "__main__":
    manager.run()
示例#16
0
 def setUp(self):
     self.app = create_app(TestConfig)
     self.app_context = self.app.app_context()
     self.app_context.push()
     # creates all database tables
     db.create_all()
示例#17
0
#!/usr/bin/env python
# encoding: utf-8
from application import create_app, celery

app = create_app(None)
app.app_context().push()
示例#18
0
文件: main.py 项目: albogdan/iotdash
#https://becominghuman.ai/full-stack-web-development-python-flask-javascript-jquery-bootstrap-802dd7d43053
#https://testdriven.io/blog/adding-a-custom-stripe-checkout-to-a-flask-app/
#https://www.tutorialspoint.com/flask/flask_templates.htm
#https://www.digitalocean.com/community/tutorials/how-to-structure-large-flask-applications
#https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world
#test out GoCD
#https://docs.sqlalchemy.org/en/13/orm/session_basics.html
#https://realpython.com/python-web-applications-with-flask-part-ii/
#https://pusher.com/tutorials/live-table-flask
"""This is the routing file - all pages of website will be directed from here"""
from application import create_app, cli

# Create the flask application
flask_app = create_app()

# Register custom CLI commands
cli.register(flask_app)

# if __name__ == "__main__":
#     flask_app.run(host='192.168.1.214', port=8081)

if __name__ == "__main__":
    flask_app.run(host='127.0.0.1', port=80)

"""
import stripe

from flask import Flask, render_template, jsonify, flash, redirect
from datetime import datetime

flask_app = Flask(__name__)
示例#19
0
 def setUp(self):
     self.app = create_app('testing')
     self.test_app = self.app.test_client()
     with self.app.app_context():
         db.create_all()
示例#20
0
 def setUp(self):
     self.app = create_app()
     self.client = self.app.test_client
示例#21
0
from application import create_app, db
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager

app = create_app('settings')

if __name__ == '__main__':

    migrate = Migrate(app, db)

    manager = Manager(app)
    manager.add_command('db', MigrateCommand)

    manager.run()
示例#22
0
def app():
    app = create_app(config='test_settings')
    return app
示例#23
0
import os

COV = None
if os.environ.get('FLASK_COVERAGE'):
    import coverage

    COV = coverage.coverage(branch=True, include='application/*')
    COV.start()

from flask.ext.migrate import Migrate, MigrateCommand
from flask.ext.script import Manager, Shell

from application import create_app, db
from application.models import User, Role, Post

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app, db)


def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role, Post=Post)


manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)


@manager.command
def test(coverage=False):
    """Run the unit tests."""
    def setUp(self):
        self.app = create_app('testing')
        self.test_app = self.app.test_client()
        with self.app.app_context():
            db.create_all()

        user = User(first_name="Johnny",
                    last_name="McSellingstuff",
                    email="*****@*****.**",
                    password="******")
        with self.app.app_context():
            db.session.add(user)
            db.session.commit()

        user = User(first_name="Jose",
                    last_name="De Los Buyingstuff",
                    email="*****@*****.**",
                    password="******")
        with self.app.app_context():
            db.session.add(user)
            db.session.commit()

        user = User(first_name="Jacques",
                    last_name="Du Purchaser",
                    email="*****@*****.**",
                    password="******")
        with self.app.app_context():
            db.session.add(user)
            db.session.commit()

        item = Item(
            user_id=1,
            title="Tea Set",
            description="Antique Tea set",
            price=140.00,
            category="furniture",
            charity="Big Cat Rescue",
            charity_url="http://www.thisisatotallyligiturl.com",
            charity_score=4,
            charity_score_image=
            "https://d20umu42aunjpx.cloudfront.net/_gfx_/icons/stars/4stars.png",
            image="img.ul",
            auction_length=5)
        with self.app.app_context():
            db.session.add(item)
            db.session.commit()

        item = Item(
            user_id=1,
            title="Rocking Chair",
            description="Vintage wood rocking chair",
            price=40.00,
            category='furniture',
            charity='Big Cat Rescue',
            charity_url="http://www.thisisatotallyligiturl.com",
            charity_score=4,
            charity_score_image=
            "https://d20umu42aunjpx.cloudfront.net/_gfx_/icons/stars/4stars.png",
            image='img.ul',
            auction_length=5)
        with self.app.app_context():
            db.session.add(item)
            db.session.commit()

        bid = Bid(item_id=1, user_id=2, amount=300.00)
        with self.app.app_context():
            db.session.add(bid)
            db.session.commit()

        bid = Bid(
            item_id=1,
            user_id=3,
            amount=400.00,
        )
        with self.app.app_context():
            db.session.add(bid)
            db.session.commit()

        bid_detail = BidDetail(bid_id=1,
                               street_address="123 Main St.",
                               city="Coshocton",
                               state="Ohio",
                               zip_code="43812",
                               receipt="image.com")
        with self.app.app_context():
            db.session.add(bid_detail)
            db.session.commit()

        bid_detail = BidDetail(bid_id=2,
                               street_address="417 Peach Ave.",
                               city="Lakeside",
                               state="Ohio",
                               zip_code="43440",
                               receipt="image.com")
        with self.app.app_context():
            db.session.add(bid_detail)
            db.session.commit()
示例#25
0
def create_test_app():
    os.environ['MODE'] = 'TESTING'
    app = create_app()
    return app
示例#26
0
"""
Файл запуска приложения.
Из ф-ла application.py импортиться ф-ция, которая создает приложение create_app
"""

from application import create_app

app = create_app('development')

if __name__ == '__main__':
    app.run()
示例#27
0
""" Server run file
This file create the flask application and starts the server
"""
import os

from application import create_app
import config

debug = config.DEBUG
host = os.getenv('IP', '0.0.0.0')
port = int(os.getenv('PORT', 8080))

app = create_app(debug)
示例#28
0
import os
from flask import Flask
from application import create_app
from sqlalchemy import create_engine
import pymysql

# To run the project in commandline please set the below environment variables
#set FLASK_CONFIG=development
#set FLASK_APP=run.py
#Then run the application as below
#flask run

config_name = os.getenv('FLASK_CONFIG')
application = create_app(config_name)

if __name__ == '__main__':
    application.run()
示例#29
0
# encoding: utf-8

# created by @cloverstd
# created at 2016-05-10 22:44

from application import create_app
from flask.ext.script import Manager
from flask.ext.migrate import Migrate, MigrateCommand
from application.models import db

app = create_app()

manager = Manager(app)

migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)


@manager.command
def run():
    """Run app."""
    app.run(
        host=app.config.get('HOST', '0.0.0.0'),
        port=app.config.get('PORT', app.config.get('PORT'))
    )


if __name__ == '__main__':
    manager.run()
示例#30
0
文件: app.py 项目: kennyr87/gigmicro
import os
from application import create_app

config_name = os.getenv('FLASK_CONFIG')

app = create_app(config_name)

if __name__ == "__main__":
    app.run()
示例#31
0
文件: base.py 项目: sungitly/isr
    def setUp(self):
        super(BaseTestCase, self).setUp()
        self.app = create_app('test')
        self.client = self.app.test_client()

        self.setup_run_in_appcontent()
示例#32
0
import os

from application import create_app

### python manage.py seed_db  to init database

app = create_app(os.getenv("FLASK_ENV") or "test")
if __name__ == "__main__":
    app.run(debug=True)
示例#33
0
from application import create_app, db, cli
from application.models import User, Post, Message, Notification, Task
# simply importing causes command decorators to run and regisrs the commands
from config import DevelopmentConfig

app = create_app(DevelopmentConfig)
cli.register(app)


@app.shell_context_processor  # registers function as shell context function
def make_shell_context():
    return {
        'db': db,
        'User': User,
        'Post': Post,
        'Message': Message,
        'Notification': Notification,
        'Task': Task
    }
示例#34
0
from flask.ext.script import Shell, Manager, Server
from flask.ext.migrate import Migrate, MigrateCommand
from application import create_app, db
from application.models import User, Task, Project, Contribution, Goal

app = create_app('development')
manager = Manager(app)
migrate = Migrate(app, db)


def make_shell_context():
    return dict(app=app, db=db, User=User, Task=Task, Project=Project,
                Goal=Goal, Contribution=Contribution)
manager.add_command('shell', Shell(make_context=make_shell_context))

# development server configuration
server = Server(host='0.0.0.0', port=8000)
manager.add_command('runserver', server)

# database migrations
manager.add_command('db', MigrateCommand)


@manager.command
def test():
    """Run the unit tests."""
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=2).run(tests)

if __name__ == '__main__':
示例#35
0
# A very simple Flask Hello World app for you to get started with...

import application

app = application.create_app()
示例#36
0
import os
from application import create_app, db
from flask.ext.script import Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app, db)

def make_shell_context():
    return dict(app=app, db=db)

manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
    manager.run()
示例#37
0
from application import create_app


app = create_app()

# if __name__ == '__main__':
#     app.run()
示例#38
0
def make_shell():
    return dict(app=create_app('settings'))
示例#39
0
# -*- coding: utf-8 -*-
import os
from flask_script import Manager
from application import create_app
from application.scripts.database import manager as db_manager

# use dev config if env var is not set
config_file_path = os.environ.get('APP_CONFIG', None) or '../configs/development.py'
manager = Manager(create_app(config_file_path))
manager.add_command('database', db_manager)


if __name__ == "__main__":
    manager.run()
示例#40
0
# -*- coding: utf-8 -*-
import os
from application import create_app
from application import db
from flask_script import Manager, Server
from flask_migrate import Migrate, MigrateCommand

# 设置默认模式
app = create_app(os.getenv('TYPE', 'default'))
host = app.config.get('HOST')
port = app.config.get('POST')

manager = Manager(app)
migrate = Migrate(app, db)

manager.add_command('runserver', Server(host=host, port=port))
manager.add_command('database', MigrateCommand)

if __name__ == '__main__':
    manager.run()
示例#41
0
    def create_app(self):
        """Create and return a testing flask app."""

        app = create_app(TestConfig)
        self.twill = Twill(app, port=3000)
        return app
示例#42
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
def test_app():
    app = create_app()
    app.config.from_object("application.config.TestingConfig")
    with app.app_context():
        yield app
示例#44
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
from application import create_app
from application.models import db
import config


app = create_app(config.Config())


# XXX: A special development route to be used to
# rebuild the database.
@app.route('/db-rebuild')
def db_rebuild():
    db.drop_all()
    db.create_all()
    return "Database rebuilt!"


if __name__ == '__main__':
    app.run(debug=True)
示例#46
0
#!/usr/bin/env python

# project imports
from application import create_app
from application.config import DevelopmentConfig


app = create_app(DevelopmentConfig)

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8000, debug=True)
示例#47
0
文件: run.py 项目: Soopro/ext_comment
import argparse

parser = argparse.ArgumentParser(
                description='Options of starting Supmice server.')

parser.add_argument('-f', '--fake',
                    dest='use_fake_data',
                    action='store_const',
                    const=True,
                    help='Allowed to use fake data for debugging.')

parser.add_argument('-t', '--test',
                    dest='server_mode',
                    action='store_const',
                    const="testing",
                    help='Manually start debug as testing config.')

parser.add_argument('-p', '--production',
                    dest='server_mode',
                    action='store_const',
                    const="production",
                    help='Manually start debug as production config.')

args, unknown = parser.parse_known_args()

app = create_app(args.server_mode or "development")

if __name__ == '__main__':
    app.use_fake_data = bool(args.use_fake_data and app.debug)
    app.run(debug=True, threaded=True, port=5001)
示例#48
0
 def setup(self):
     self.app = create_app('testing')
     self.client = self.app.test_client()
     self.ctx = self.app.test_request_context()
     self.ctx.push()
     db.create_all()
示例#49
0
import sys
from application import create_app

if __name__ == "__main__":
    if len(sys.argv) == 2 and sys.argv[1] == "--debug":
        app = create_app(debug=True)
        app.run(debug=True)
    else:
        app = create_app()
        app.run()
else:
    app = create_app()
示例#50
0
def simple_run(config):
    app = create_app(config)
    app.run(host="0.0.0.0", port=9192, debug=True)
示例#51
0
#!/usr/bin/env python

# project imports
from application import create_app
from application.config import DeploymentConfig


app = create_app(DeploymentConfig)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)
from application import create_app
from config import *
from decouple import config as config_decouple

enviroment = config['development']
if config_decouple('PRODUCTION', default=False):
    enviroment = config['production']

app = create_app(enviroment)
示例#53
0
def testCreateApp(self):
    return create_app('core.TestConfig')
示例#54
0
from flask import Flask, g, session, jsonify, flash, redirect, url_for

from config import config, AppConfig
from flask_script import Manager, Server, Shell
from flask_migrate import Migrate, MigrateCommand
import os

from api.models import User
from flask_github import GitHubError
from api.utils.db import db

from application import create_app

app = create_app(os.getenv('FLASK_ENV', 'development'))
migrate = Migrate(app, db)
manager = Manager(app)


@app.errorhandler(GitHubError)
def jumpship(error):
    session.pop('user_id', None)
    flash('Something bad happened. Please try again?', 'error')
    return redirect(url_for('user_app.index'))


@app.before_request
def before_request():
    g.user = None
    if 'user_id' in session:
        user_id = session['user_id']
        get_user = lambda user_id: User.query.filter_by(username=user_id).first() or\
示例#55
0
import os

from flask.ext.migrate import MigrateCommand, Migrate
from flask.ext.script import Manager, Shell
from sqlalchemy import func
from termcolor import colored, cprint

from application import create_app, db
from application.utils import logsql
from commands.add_dev_data import AddDevData
from commands.create_admin import CreateAdmin
from commands.runserver import Runserver

config_file_path = os.environ.get('APP_CONFIG', None) or '../dev_config.py'

app = create_app(config_file_path)

manager = Manager(app)
migrate = Migrate(app, db)

manager.add_command('db', MigrateCommand)
manager.add_command('create_admin', CreateAdmin())
manager.add_command('add_dev_data', AddDevData())
manager.add_command('runserver', Runserver())


def _make_context():
    """
    Return context dict for a shell session so one can access
    stuff without importing it explicitly.
    """
示例#56
0
def run():
    os.environ['FLASK_ENV'] = 'development'
    os.environ['FLASK_RUN_FROM_CLI'] = 'false'
    app = create_app()
    app.run(debug=True)
示例#57
0
 def __init__(self):
     app = create_app()
     self.app = app
示例#58
0
from application import create_app

application = create_app()

#from myproject import application

if __name__ == "__main__":
    application.run()
示例#59
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from application import create_app
app = create_app('settings')

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=5000)

示例#60
0
from application import create_app

if __name__ == '__main__':
    app = create_app(config='config')
    app.run(host='127.0.0.1', port='3000')