Ejemplo n.º 1
0
def drive_client():
    creds = _get_drive_creds()

    new_client = build('drive', 'v3', credentials=creds)
    try:
        yield new_client
    except Exception:
        logger.exception("Error with the client")
        raise
Ejemplo n.º 2
0
async def session(**kwargs) -> AsyncGenerator[AsyncSession, None]:
    new_session = AsyncSession(**kwargs, bind=engine, expire_on_commit=False)
    try:
        yield new_session
        await new_session.commit()
    except Exception as e:
        logger.exception("Error with the session")

        await new_session.rollback()
        raise DatabaseError(e)
    finally:
        await new_session.close()
Ejemplo n.º 3
0
async def validation_exception_handler(request: Request,
                                       exc: RequestValidationError):
    logger.exception("Validation error occurred, %s", str(exc))

    context = {
        "request": request,
        "error": {
            "type": exc.__class__.__name__,
            "args": exc.args,
            "json": exc.json(indent=4)
        }
    }

    return templates.TemplateResponse("errors/500.html", context)
Ejemplo n.º 4
0
async def database_exception_handler(request: Request,
                                     exc: database.DatabaseError):
    logger.exception("Error, %s", str(exc))

    context = {
        "request": request,
        "error": {
            "type": exc.__class__.__name__,
            "args": exc.args,
            "json": f"Database error: {exc}"
        }
    }

    return templates.TemplateResponse("errors/500.html", context)
Ejemplo n.º 5
0
    """ Get pairs: (date, info) of all days from start to stop.

    If the day is empty, material_id is supposed
    as the material_id of the last not empty day.
    """
    logger.debug("Getting data from log")

    if not (log_records := await get_log_records()):
        return

    # stack for materials
    materials: list[UUID] = []
    try:
        completion_dates = await get_completion_dates()
    except Exception as e:
        logger.exception(e)
        completion_dates = {}

    step = datetime.timedelta(days=1)
    iter_over_dates = min(log_records.keys())

    while iter_over_dates <= database.today().date():
        last_material_id = safe_list_get(materials, -1, None)

        if ((completion_date := completion_dates.get(last_material_id))
                and completion_date < iter_over_dates):
            materials.pop()
            last_material_id = safe_list_get(materials, -1, None)

        if not (info := log_records.get(iter_over_dates)):
            info = LogRecord(material_id=last_material_id, count=0)
Ejemplo n.º 6
0
async def http_exception_handler(request: Request, exc: HTTPException):
    logger.exception("HTTP exception occurred, %s", str(exc))

    context = {"request": request, "what": repr(exc)}

    return templates.TemplateResponse("errors/404.html", context)