예제 #1
0
파일: app.py 프로젝트: traumschule/pubgate
def create_app(config_path):

    app = Sanic(error_handler=PGErrorHandler())
    app.config.from_pyfile(config_path)

    app.config.DOMAIN = os.environ.get("DOMAIN", app.config.DOMAIN)
    app.base_url = f"{app.config.METHOD}://{app.config.DOMAIN}"
    # app.streams = Streams()
    db_host = os.environ.get("MONGODB_HOST", "localhost")
    app.config.MOTOR_URI = f'mongodb://{db_host}:27017/pbgate'
    BaseModel.init_app(app)
    CORS(app, automatic_options=True)

    # TODO Find viable openapi fork
    app.blueprint(swagger_blueprint)

    # app.blueprint(instance)
    app.blueprint(well_known)
    app.blueprint(user_v1)
    app.blueprint(inbox_v1)
    app.blueprint(outbox_v1)

    app.register_listener(setup_cached_user, 'before_server_start')

    # app.add_task(register_client(app))
    # app.add_task(register_admin(app))

    if app.config.get('USER_ON_DEPLOY'):
        app.register_listener(setup_on_deploy_user, 'before_server_start')

    register_extensions(app)

    app.static('/media', MEDIA)

    return app
예제 #2
0
파일: main.py 프로젝트: qyt2018/shiba
def make_app():
    app = Sanic(__name__)
    app.config.from_object(config)
    app.static('/_nuxt', app.config['NUXT_STATIC_DIR'])
    for url in urlpatterns:
        app.add_route(url[1], url[0])

    BaseModel.init_app(app)
    return app
예제 #3
0
def create_app(configuration=Configuration):
    app = Sanic(__name__)
    CORS(app)

    app.blueprint(rest)
    app.config.from_object(configuration)
    BaseModel.init_app(app)

    return app
예제 #4
0
def initialize_model(db_uri, app):
    """
    Initializes the connectoin to the backend database

    @param db_uri: connection string to the mongodb instance
    @param app: Sanic application object
    """
    settings = {
        'MOTOR_URI': db_uri
    }
    app.config.update(settings)
    BaseModel.init_app(app)
예제 #5
0
def setup_mongodb(app: Sanic):
    motor_settings = {
        'MOTOR_URI': app.config['DATABASE_URL'] + '/' + MONGO_DB_NAME,
        'LOGO': None,
    }
    app.config.update(motor_settings)
    BaseModel.init_app(app)

    @app.listener('before_server_start')
    async def connect_to_db(*args):
        app.db = AsyncIOMotorClient(app.config['DATABASE_URL'])[MONGO_DB_NAME]

    @app.listener('after_server_stop')
    async def disconnect_from_db(*args):
        pass
예제 #6
0
def create_app(config_path):

    app = Sanic(error_handler=PGErrorHandler())
    app.config.from_pyfile(config_path)
    app.base_url = f"{app.config.METHOD}://{app.config.DOMAIN}"
    BaseModel.init_app(app)

    # TODO Find viable openapi fork
    app.blueprint(openapi_blueprint)
    app.blueprint(swagger_blueprint)

    # app.blueprint(instance)
    app.blueprint(well_known)
    app.blueprint(user_v1)
    app.blueprint(inbox_v1)
    app.blueprint(outbox_v1)

    app.add_task(register_client(app))
    app.add_task(register_admin(app))
    register_extensions(app)

    return app
예제 #7
0
import hashlib
import time

from bson import ObjectId
from sanic import Sanic
from sanic.exceptions import abort
from sanic.request import Request
from sanic.response import json, text
from sanic.views import HTTPMethodView
from sanic_motor import BaseModel
from sanic_jwt import initialize, protected, exceptions

app = Sanic('some_name')
app.config.update({"MOTOR_URI": "mongodb://localhost:27017/myapp"})
BaseModel.init_app(app)


class User(BaseModel):
    __coll__ = "users"
    __unique_fields__ = ['username']


class Post(BaseModel):
    __coll__ = "posts"


def hash_password(password: str):
    salt = "x2Q!T-3(pmrsNcBMeKA0MS!7ZQgcv_Jy"  # This should be private!
    return hashlib.sha512((password + salt).encode("ascii")).hexdigest()

예제 #8
0
        "ACLIENTS_REDIS_PORT": environ_data.get("ACLIENTS_REDIS_PORT", 6380),
        "ACLIENTS_REDIS_DBNAME": environ_data.get("ACLIENTS_REDIS_PORT", 0),
        "ACLIENTS_REDIS_PASSWD": environ_data.get("ACLIENTS_REDIS_PASSWD", ""),
        "ACLIENTS_REDIS_POOL_SIZE": environ_data.get("ACLIENTS_REDIS_POOL_SIZE", 10),

        'ACLIENTS_MYSQL_HOST': environ_data.get("ACLIENTS_MYSQL_HOST", "127.0.0.1"),
        'ACLIENTS_MYSQL_PASSWD': environ_data.get("ACLIENTS_MYSQL_PASSWD", "abcd1234"),
        'ACLIENTS_MYSQL_USERNAME': environ_data.get("ACLIENTS_MYSQL_USERNAME", "root"),
        'ACLIENTS_MYSQL_PORT': environ_data.get("ACLIENTS_MYSQL_PORT", 3306),
        'ACLIENTS_MYSQL_DBNAME': environ_data.get("ACLIENTS_MYSQL_DBNAME", "test"),
        'ACLIENTS_MYSQL_POOL_SIZE': environ_data.get("ACLIENTS_MYSQL_POOL_SIZE", 50),

        'MOTOR_URI': environ_data.get("MOTOR_URI", 'mongodb://*****:*****@localhost:27017/test'),
    }
)
mon_db = BaseModel()
mon_db.init_app(app)
redis_conn_0.init_app(app)
redis_conn_1.init_app(app)
db_sql.init_app(app)
app.db = db_sql
app.mon_db = mon_db
app.redis_conn_0 = redis_conn_0
app.redis_conn_1 = redis_conn_1

# cors = CORS(app, resources={r"/apis/*": {"origins": "*"}})

bp_group = Blueprint.group(api, url_prefix='')
app.blueprint(bp_group)

# app.register_listener(setup_mysql, 'before_server_start')
예제 #9
0
 def add_db(app: Sanic) -> Sanic:
     """
     Base method for adding db in the instance of core
     """
     BaseModel.init_app(app)
     return app
예제 #10
0
 def init_app(app, open_listener='before_server_start',
              close_listener='before_server_stop', name=None, uri=None):
     BaseModel.init_app(app, open_listener, close_listener, name, uri)
     [entity.set_coll()
      for entity in ExtendedModel.__entities__
      if not isinstance(entity, ExtendedModel)]
예제 #11
0
\- **Every 1 minute** for YouTube/Twitch/Twitcasting Live Streams data.
\- **Every 2 minutes** for YouTube Upcoming Streams data.
\- **Every 2 minutes** for BiliBili Live Streams data.
\- **Every 4 minutes** for BiliBili Upcoming Streams data.
\- **Every 6 hours** for Channels Info/Stats.<br><br>"""  # noqa: W605,E501
API_DESC_END = """You could contact me at **Discord**: _N4O#8868_
If you need more Other VTubers to add to the list."""

app.config.update(settings)
API_DESC += API_DESC_END

app.config["API_DESCRIPTION"] = API_DESC
app.config.FORWARDED_SECRET = "e51bfddc277b46a194f81c146b3b4606"  # Used for reverse proxy

logger.info("Connecting to database...")
BaseModel.init_app(app, name="vtbili", uri=app.config["MOTOR_URI"])

logger.info("Getting database server version...")
sync_dbconn = MongoClient(app.config["MOTOR_URI"])
db_serverinfo = sync_dbconn.server_info()
app.config["MONGODB_DBVERSION"] = db_serverinfo["version"]

HOMEPAGE_HEADERS = r"""<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <title>ihateanime API</title>
    <meta name="description" content="A simple BiliBili Scheduler API Endpoint focused on VTubers">
    <meta name="theme-color" content="#383838">
def dataAccessFactory(app):
    BaseModel.init_app(app)