Exemplo n.º 1
0
from entities import db as database, User as UserEntity
from flask import Flask
from flask_login import LoginManager, UserMixin
from pony.orm import db_session, set_sql_debug
from uuid import UUID


# application

application = Flask(__name__)


# database

database.bind(**config.get('database_bindings', {'provider': 'sqlite', 'filename': ':memory:'}))
set_sql_debug(config.get('debug_mode', False))
database.generate_mapping(create_tables=config.get('create_tables', True))


# authentication

application.config['SECRET_KEY'] = config.get('secret_key')
login_manager = LoginManager(application)


class LoginUser(UserMixin):
    def __init__(self, user_entity: UserEntity):
        self.id = user_entity.id
        self.name = user_entity.name
        self.administrator = user_entity.administrator
Exemplo n.º 2
0
    first_name = orm.Required(str)
    is_bot = orm.Required(bool)
    last_name = orm.Optional(str)
    username = orm.Optional(str)
    language_code = orm.Optional(str)


class Offer(db.Entity):
    shop = orm.Required('Shop')
    item = orm.Required(str)
    price = orm.Required(int)
    mana = orm.Required(int)


class Shop(db.Entity):
    link = orm.Required(str)
    name = orm.Required(str)
    ownerName = orm.Required(str)
    ownerCastle = orm.Required(str)
    kind = orm.Required(str)
    mana = orm.Required(int)
    offers = orm.Set(Offer)


if config.APP_ENV and config.APP_ENV.startswith('PROD'):
    db.bind(**config.DB_PARAMS)
else:
    orm.set_sql_debug(True)
    db.bind('sqlite', 'shops.sqlite', create_db=True)
db.generate_mapping(create_tables=True)
Exemplo n.º 3
0
from pony.orm import PrimaryKey, Required, Optional, Database, commit, set_sql_debug, db_session, select

settings = dict(provider='sqlite', filename='valutes.db', create_db=True)
db = Database(**settings)
set_sql_debug(True)


class Valutes(db.Entity):
    id = PrimaryKey(int, auto=True)
    char_code = Required(str)
    date = Required(str)
    to_usd = Optional(float)
    to_eur = Optional(float)
    to_cny = Optional(float)
    to_jpy = Optional(float)
Exemplo n.º 4
0
from pony.orm import db_session, set_sql_debug, Database, PrimaryKey,\
    Required, select, TransactionIntegrityError

set_sql_debug(False)
db = Database()


class User(db.Entity):
    tguser_id = PrimaryKey(int)
    tgusername = Required(str)
    tgfirstname = Required(str)


class Show(db.Entity):
    show_id = PrimaryKey(int)
    title = Required(str, unique=True)
    link = Required(str, unique=True)
    airing_day = Required(str)
    airing_time = Required(str)


class Subscription(db.Entity):
    ext_user_id = Required(int)
    ext_show_id = Required(int)
    sub_id = PrimaryKey(ext_user_id, ext_show_id)


db.bind(provider='sqlite', filename='data.db', create_db=True)
db.generate_mapping(create_tables=True)

Exemplo n.º 5
0
def pytest_sessionstart(session):
    db.bind(provider='sqlite', filename=':memory:')
    db.generate_mapping(create_tables=True)
    set_sql_debug(True)
Exemplo n.º 6
0

if __name__ == '__main__':
    print('> Starting Santa Bot...')

    bot_token = getenv('BOT_TOKEN')
    if not bot_token:
        raise Exception(
            'Error: Expected a BOT_TOKEN, got {0}. Did you set up .env?'
            .format(bot_token)
        )

    # TODO: Convert this bool check to a function or something
    use_sqlite = getenv('USE_SQLITE', 'True').lower() == 'true'
    sql_debug = getenv('SQL_DEBUG', 'False').lower() == 'true'
    orm.set_sql_debug(sql_debug)

    print('> Initialising database connection...')
    if use_sqlite:
        print('> Using SQLite DB for testing.')
        santa.db.bind(
            provider='sqlite',
            filename='santabot.db',
            create_db=True
        )
    else:
        print('> Using PostgreSQL DB.')
        db_host = getenv('DB_HOST', default='127.0.0.1')
        db_port = getenv('DB_PORT', default='5432')
        db_name = getenv('DB_NAME')
        db_user = getenv('DB_USER')