Beispiel #1
0
async def run_scheduler_async(config: Config):
    db_config = get_db_config()
    logger_configure(level=config.LOG_LEVEL.value,
                     root_level=config.LOG_ROOT_LEVEL.value)
    async with VisitScheduler(config.SCHEDULER,
                              time_zone=db_config.TIME_ZONE) as scheduler:
        await scheduler.run()
Beispiel #2
0
import io
import uuid
import shutil
from pathlib import Path
from typing import Union

from configs import get_db_config

config = get_db_config()


class ImageStorage:

    root_path = config.MEDIA_DIR

    def __init__(self, folder: str):
        self.folder = self.root_path / folder

    def save(self, file: Union[io.IOBase, Path]) -> Path:
        self.folder.mkdir(parents=True, exist_ok=True)
        file_name = self._get_file_name(file.name)
        file_path = self.folder / file_name

        if isinstance(file, Path):
            shutil.copy(file, file_path)
        else:
            file.seek(0)
            mode = 'w' if isinstance(file, io.StringIO) else 'wb'
            with file_path.open(mode) as opened_file:
                opened_file.write(file.read())
Beispiel #3
0
async def setup():
    config = get_db_config()
    await Tortoise.init(config=TORTOISE_ORM, timezone=config.TIME_ZONE)
    await Tortoise.generate_schemas()